我在“/”中有一个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
'如果我们使用无效的url,它将被重定向到'登录.action'
页面,但登录后,在使用无效网址时,我从 tomcat 收到 HTTP Status 404
错误,而不是重定向到“Ledger.action
” '
在 eclipse 控制台中,我收到如下错误:
SEVERE: Exception Processing ErrorPage[errorCode=404, location=/index.jsp] org.apache.jasper.JasperException: A request made it through to some part of Stripes without being wrapped in a StripesRequestWrapper. The StripesFilter is responsible for wrapping the request, so it is likely that either the StripesFilter is not deployed, or that its mappings do not include the DispatcherServlet and *.jsp. Stripes does not require that the Stripes wrapper is the only request wrapper, or the outermost; only that it is present.
以下是我的 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>
最佳答案
我必须在 web.xml 的过滤器映射部分添加以下内容:
<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
关于java - Stripes 异常处理程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7333100/