Stripes异常处理程序错误

时间:2011-09-07 11:28:45

标签: java java-ee exception-handling stripes

我在“/”中有一个index.jsp文件,内容如下:

<%@include file="/WEB-INF/jsp/common/taglibs.jsp" %>

    <c:choose>
        <c:when test='<%=session.getAttribute("consumer") != null%>'>
            <jsp:forward page="/Ledger.action"/>
        </c:when>
        <c:otherwise>
            <jsp:forward page="/Login.action"/>             
        </c:otherwise>
    </c:choose>

在我的web.xml文件中,我放置了一个这样的条目:

  <error-page>
    <error-code>404</error-code>
    <location>/index.jsp</location>
  </error-page>

我编写了一个自定义异常处理程序,如下所示:

public class MyExceptionHandler extends DefaultExceptionHandler {
    public Resolution catchActionBeanNotFound(
                ActionBeanNotFoundException exc,
                HttpServletRequest request,
                HttpServletResponse response
            ) {
        return new ErrorResolution(HttpServletResponse.SC_NOT_FOUND);
    }
}

如果用户未登录,则表示“session.getAttribute("consumer") == null”,如果我们使用无效网址,则会将其重定向到'Login.action'页面,但在登录后,使用无效网址时我是从tomcat收到HTTP Status 404错误,而不是重定向到“Ledger.action

在eclipse控制台中,我收到如下错误:

  

SEVERE:异常处理ErrorPage [errorCode = 404,   location = / index.jsp] org.apache.jasper.JasperException:发出请求   它通过Stripes的某些部分而不被包裹在一起   StripesRequestWrapper。 StripesFilter负责包装   请求,所以很可能StripesFilter不是   已部署,或其映射不包含DispatcherServlet    * .jsp。 Stripes不要求Stripes包装器   只请求包装,或最外层;只有它存在。

以下是我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <context-param>
        <param-name>
            javax.servlet.jsp.jstl.fmt.localizationContext
        </param-name>
        <param-value>
            StripesResources
        </param-value>
    </context-param>

    <filter>
        <filter-name>StripesFilter</filter-name>
        <filter-class>
            net.sourceforge.stripes.controller.StripesFilter
        </filter-class>
        <init-param>
            <param-name>ActionResolver.Packages</param-name>
            <param-value>org.firm.www.action</param-value>
        </init-param>
        <init-param>
            <param-name>Extension.Packages</param-name>
            <param-value>org.firm.www.ext</param-value>
        </init-param>
    </filter>
  <servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>
      net.sourceforge.stripes.controller.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>Kaptcha</servlet-name>
    <servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
    <init-param>
        <param-name>kaptcha.image.width</param-name>
        <param-value>160</param-value>
    </init-param>
    <init-param>
        <param-name>kaptcha.image.height</param-name>
        <param-value>75</param-value>
    </init-param>
    <init-param>
        <param-name>kaptcha.textproducer.font.names</param-name>
        <param-value>Tahoma,Arial</param-value>
    </init-param>
    <init-param>
        <param-name>kaptcha.textproducer.font.color</param-name>
        <param-value>255,153,0</param-value>
    </init-param>
    <init-param>
        <param-name>kaptcha.noise.impl</param-name>
        <param-value>org.kwa.www.extras.NoNoise</param-value>
    </init-param>
    <init-param>
        <param-name>kaptcha.border</param-name>
        <param-value>no</param-value>
    </init-param>
    <init-param>
        <param-name>kaptcha.background.clear.from</param-name>
        <param-value>51,51,51</param-value>
    </init-param>
    <init-param>
        <param-name>kaptcha.background.clear.to</param-name>
        <param-value>51,51,51</param-value>
    </init-param>
  </servlet>

  <filter-mapping>
    <filter-name>StripesFilter</filter-name>
    <servlet-name>DispatcherServlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>

  <servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>*.action</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>Kaptcha</servlet-name>
    <url-pattern>/kaptcha.jpg</url-pattern>
  </servlet-mapping>

    <display-name>OnlinePayment</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
      <error-page>
        <error-code>404</error-code>
        <location>/index.jsp</location>
      </error-page>
</web-app>

1 个答案:

答案 0 :(得分:3)

我必须在web.xml的filter-mapping部分添加以下内容:

<dispatcher>ERROR</dispatcher>

然后整个条目看起来像:

  <filter-mapping>
    <filter-name>StripesFilter</filter-name>
    <servlet-name>DispatcherServlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>ERROR</dispatcher>
  </filter-mapping>

我已经找到了link

的答案