Struts2和Jersey在单个web应用程序中产生http500错误



它显示了带有jasper错误的http 500,在启动应用程序时,我在同一项目中使用jersey和struts2。需要任何特定的配置。尽管所有jar文件都包含在内,但它显示了错误。

Web.xml

       <?xml version="1.0" encoding="UTF-8"?>
       <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>RestExample</display-name>
    <welcome-file-list>
        <welcome-file>/jsp/login.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.src.matchmaker.services</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>*.action</url-pattern>
    </filter-mapping>
</web-app>

struts.xml

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<constant name="struts.action.excludePattern" value="/rest/.*" />
    <!-- Configuration for the default package. -->
    <package name="default" extends="struts-default">

    </package>
</struts>

login.jsp

    <%-- 
    Document   : register
    Created on : Jan 31, 2013, 11:18:43 AM
    Author     : wifin
![enter image description here][1]--%>
<%@page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="<%=request.getContextPath()%>/css/match_login_style.css" type="text/css">
        <link rel="icon" type="image/jpg" href="<%=request.getContextPath()%>/images/logo.jpg"/>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Login</title>
        <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.7.2.js"></script>
        <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.validation.js"></script>
        <script type="text/javascript" src="<%=request.getContextPath()%>/js/login_validation.js"></script>
    </head>
    <body>
        <div class="wrap">
            <div class="back" align="center">
                <form id="login" name="login" action="login.action" method="post">
                    <div align="center" class="header">Login</div>
                    <div id="err"><s:actionerror/></div>
                    <div class="tit">
                        Email Id: <input type="text" name="emailId" id="emailId"/>
                        <div class="clr"></div>
                    </div>
                    <div class="tit">
                        Password: <input type="password" name="password" id="password"/>
                        <div class="clr"></div>
                    </div>
                    <div> 
                        <input class="btn" type="submit" name="reg" value="Login" id="reg" />
                        <input class="btn" type="reset" value="Cancel" id="cancel" />
                    </div>
                </form>
                <div><a class="link" href="<%=request.getContextPath()%>/jsp/register.jsp">New User?</a></div>
            </div>
        </div>
    </body>
</html>

显示页面时没有经过Struts2过滤器。您需要调用Struts2操作,该操作将显示您的页面。

此外,自Struts2.1.3以来,org.apache.struts2.dispatcher.FilterDispatcher也被弃用,因此,如果您使用的版本高于2.1.3,请将FilterDispatcher更改为org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

为什么不使用这个过滤器拦截所有的url模式呢?将此筛选器<url-pattern>更改为<url-pattern>/*</url-pattern>

BTW在JSP中使用scriptlet是一种糟糕的做法,请改用Struts2标记。

最新更新