Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Session Attribute works but why not Request Attribute  RSS feed

 
praveen sharma
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 Jsp pages,first.jsp and second.jsp.
Inside first.jsp page I am setting 2 attributes
name field in session scope and address field in request Scope.
and i made a link on click of which second.jsp page will be displayed.

Inside second.jsp page i am getting Session Scope attribute but request attribute is null .

I understood why session is working because Jsp page has session object by default.But why request Scope is not working since request is going on from 1 jsp page to another jsp page.

Kindly Reply.
Your feedback is valuable to me

Praveen Sharma
SCJP1.4
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each JSP has its own request. Once the response is sent to the browser, a request goes out of scope.
 
praveen sharma
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry dude,
I could not understood yours response so kindly explain it.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JSP creates an HTML page to be sent to the browser as the response. Once sent to the browser, the request is destroyed. So scoped variables on that request go away as well.
 
ramanuja varun
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
probably you have to set those attributes using request.setAttribute method then you will be able to access them.I hope i am right
 
ramanuja varun
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry dude i am wrong.
 
yilmaz uksal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should use jsp:forward standard action when going to second.jsp. That way you will keep the same request object and its attributes
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by yilmaz uksal:
you should use jsp:forward standard action when going to second.jsp. That way you will keep the same request object and its attributes
No, that would be silly. Doing so would never let the response display in the browser between the pages, and would likely result in an exception.
 
Srikanth Nutigattu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To make things little clear,
I think you have misunderstood "Request scope", when you type the URL of first.jsp, that is the FIRST request, and when you "click" on the link of second.jsp that is SECOND request, hence the attributes you set in FIRST request will not be available for SECOND request.

Hope things are clear now...
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!