• Post Reply Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher now working as expected  RSS feed

 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you also post the code that you are using to bind the bean to session scope?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition, please send the condition statement where you are figuring out that the session variable is not found.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!