0

它显示带有碧玉错误的 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>

登录.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>
4

1 回答 1

0

您的页面正在显示而无需通过 Struts2 过滤器。您需要调用 Struts2 操作,结果将显示您的页面。

自 Struts 2.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>.

顺便说一句,在 JSP 中使用 scriptlet 是一种不好的做法,请改用 Struts2 标记。

于 2013-02-06T22:10:34.363 回答