Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

RequestDispatcher now working as expected

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you also post the code that you are using to bind the bean to session scope?
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In addition, please send the condition statement where you are figuring out that the session variable is not found.
 
I am displeased. You are no longer allowed to read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic