Question

I have an index.jsp file in "/" with content as follows:

<%@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>

In my web.xml file I have placed an entry like this:

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

I have written a custom exception handler as follows:

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

When the users are not signed in, means 'session.getAttribute("consumer") == null' if we use an invalid url, it will be redirected to the 'Login.action' page, but after signing in, on using invalid urls I am getting a HTTP Status 404 error from tomcat instead of redirecting to 'Ledger.action'

In eclipse console, I am getting an error as follows:

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.

Following is my web.xml file:

<?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>
Was it helpful?

Solution

I had to add the following in filter-mapping section of web.xml:

<dispatcher>ERROR</dispatcher>

Then the whole entry will look like:

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

I have found the answer on this link

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top