[jboss-jira] [JBoss JIRA] Commented: (JBAS-4303) Web session is empty when forwarding request to another web context.

Penkov Vladimir (JIRA) jira-events at lists.jboss.org
Thu Apr 5 08:54:58 EDT 2007


    [ http://jira.jboss.com/jira/browse/JBAS-4303?page=comments#action_12358494 ] 
            
Penkov Vladimir commented on JBAS-4303:
---------------------------------------

Workaround:

Create filter:
======================
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Enumeration;

public class SessionBug implements Filter {

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;
        Enumeration e = request.getSession().getAttributeNames();
        while (e.hasMoreElements()) {
            String name = (String) e.nextElement();
            request.setAttribute("sessionbug."+name, request.getSession().getAttribute(name));
        }
        chain.doFilter(req, resp);
    }
}
======================
add in web.xml:
======================
    <filter>
        <filter-name>SessionBugJBAS4303</filter-name>
        <filter-class>imagewarehouse.web.filter.SessionBug</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>SessionBugJBAS4303</filter-name>
        <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
======================

Now you can get session attribute from request in jsp:
======================
<%
    request.setAttribute("client", request.getAttribute("sessionbug."+Constants.CLIENT_KEY));
%>
======================


> Web session is empty when forwarding request to another web context.
> --------------------------------------------------------------------
>
>                 Key: JBAS-4303
>                 URL: http://jira.jboss.com/jira/browse/JBAS-4303
>             Project: JBoss Application Server
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: Web (Tomcat) service
>    Affects Versions: JBossAS-4.0.4.GA
>         Environment: Fedora Core 6
>            Reporter: Penkov Vladimir
>         Assigned To: Remy Maucherat
>
> I have following in web.xml:
> =====================
>     <servlet>
>         <servlet-name>Redirector</servlet-name>
>         <servlet-class>web.servlet.Redirector</servlet-class>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>Redirector</servlet-name>
>         <url-pattern>/redirect.do</url-pattern>
>     </servlet-mapping>
>     <error-page>
>         <error-code>404</error-code>
>         <location>/redirect.do</location>
>     </error-page>
> =====================
> It is located in /deploy/web.jar. It is deployed under / context.
> My jsp are in dir: /deploy/resources.war/, deployed under /resources.
> In Redirector I do:
> ==============
>         String url = (String) request.getAttribute("javax.servlet.error.request_uri");
>         String contextPath = (String) context.getAttribute("/resources");
>         ServletContext c = context.getContext(contextPath);
>         RequestDispatcher disp = c.getRequestDispatcher(url);
>         disp.forward(request, response);
> ==============
> So now I can reach my jsp in another context.
> In servlet Login I do:
> =============
>     ClientManager manager = new ClientManager();
>     Client client = manager.findClientByLogin(login);
>     if (client!=null && client.getPassword().equals(password)) {
>             request.getSession().setAttribute(CLIENT_KEY, client);
>     }
>     response.sendRedirect("/private/index.jsp");
> =============
> in /deploy/resources.war/private/index.jsp I have:
> ================
> <%
>     Enumeration e = request.getSession().getAttributeNames();
>     System.out.println("element names:");
>     while (e.hasMoreElements()) {
>         System.out.println("e.nextElement() = " + e.nextElement());
>     }
> %>
> ================
> And I recieve no elements in session. 
> Variables, sent in the request attributes, are accessible fine.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list