Discussions

Web tier: servlets, JSP, Web frameworks: Problem with Filter and Struts

  1. Problem with Filter and Struts (3 messages)

    I´m starting with Struts and i'm having a problem using at the same time a filter and Struts. My filter intercepts all the requests to see if the user is logged in. If not, the user is dispatched to the login page, otherwise the acess to the desired resource is granted. I have the follwing code in my filter:

     // Not to filter the login
     if(!GenericValidator.isBlankOrNull(pathResource)) {
        if (pathResource.endsWith("/login.do")) {
          filterChain.doFilter(servletRequest, servletResponse);
          return;
         }
     }

     So I want not to filter the user authentication with this code above. But after the the return statement gets executed the request doesn't reach my action, it seems that it's processed and every time I am faced with the index page again. The code of my action isn't executed. Here is my struts-config.xml for this:

     <form-bean name="myForm"
        type="org.apache.struts.validator.DynaValidatorForm">
           <form-property name="login" type="java.lang.String"/>
           <form-property name="passw" type="java.lang.String"/>
     </form-bean>

    <action
      attribute="myForm"
      input="/index.jsp"
      name="myForm"
      path="/login"
      scope="request"
      type="br.com.rafael.myproject.action.LoginAction">
      <forward name="main_page" path="/main_page.jsp"/>
    </action>

    Can anyone help me with this problem?
    Tks, Rafael Naufal.

    Threaded Messages (3)

  2. Problem with Filter and Struts[ Go to top ]

    Hi,

    One thing I would look at is the scope of your form. Currently it looks like you have it in the Request scope...so data in your form is only valid for 1 request. Try changing the scope to session...

    M
  3. Problem with Filter and Struts[ Go to top ]

    assuming the java code is inside your filter,

    you have to call the rest of the filters to continue..

    like..

     chain.doFilter(req, res);

    instead of the return
  4. re Problem with Filter and Struts[ Go to top ]

    because you use the DynaValidatorForm,so the pathResource.endsWith("/login.do") always retrun a "false"status. because the pathResource may content the "?login=**&passw=**"

    if (pathResource.endsWith("/login.do")) {
          filterChain.doFilter(servletRequest, servletResponse);
          return;
         }