aspose file tools*
The moose likes JSP and the fly likes RequestDispatcher now working as expected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "RequestDispatcher now working as expected" Watch "RequestDispatcher now working as expected" New topic
Author

RequestDispatcher now working as expected

Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
I have a simple bean that I�m storing in a session (say- page1.jsp) and then forwarding the request to another web component (say- page2.jsp); wherein I�m checking for the session attribute. In case the attribute is not found, I�m redirecting the client to the login page (say- login.jsp).

It�s strange to note that when I�m forwarding (a RequestDispatcher forward() call) the request after storing attribute in the session (in page1.jsp); every time when I open a new browser window and directly try to access page2.jsp I don�t get redirected to the login page, but, when I do a redirection form page1.jsp, and then I open a new browser window (trying to access page2.jsp), I get redirected to the login page.

I know that the basic difference between a redirect and a forward is that the former makes a roundtrip to the server, whereas, a forward call does a request forwarding at the server end and the address bar of the browser window remains unchanged.

But, I still don�t get that why Server Side Forwarding is not working here.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Does your browser have cookies disabled?
If so you're starting a new session with each request to the server.

Put the following tag in each of your JSPs and compare your session ID.
<%=session.getId()%>

The LiveHTTPHeaders plugin for Firefox is also a nice tool for debugging these types of issues.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Hi Ben,
Thanks for the post.

Yes cookies are enabled in my web browser. BTW, I tried both- IE and Firefox, but got similar results.

Thanks,
Kunal
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10289
    
168

I have a simple bean that I�m storing in a session (say- page1.jsp) and then forwarding the request to another web component (say- page2.jsp); wherein I�m checking for the session attribute. In case the attribute is not found, I�m redirecting the client to the login page (say- login.jsp).


Can you post that part(s) of your code where you are doing this logic


[My Blog] [JavaRanch Journal]
Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Hello All,
Following is the simple code i'm using:


My query is that when I do a RequestDispatcher.forward() call, each request looks like a new one (cause I get nulls in the showCart.do resource). However, sendRedirect() works well.

Any help shall be highly appreciated.

Thanks,
Reema
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Can you also post the code that you are using to bind the bean to session scope?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
In addition, please send the condition statement where you are figuring out that the session variable is not found.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispatcher now working as expected