Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Request in Session

 
Weerawit Maneepongsawat
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i put Request object in the Session object like this.
session.setAttribute("page1", request);
after pass 2 page i want to get page1 again i use
HttpServletRequest page1 = (HttpServletRequest) session.getAttribute("page1");
Is it work ??
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want to do something like that? it doesn't make sense to me
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a round-about way, Andres is saying that no, you can't do that.
A request object is only valid until you have sent your response, and that's it. It certainly wouldn't be a good idea to try to hold onto it and do anything with it during rubsequent requests.
Dave
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One alternative you might want to consider is to use the RequestDispatcher.forward(reqest, response) method from the ServletContext(application). You can wrap your page 2 resource in a RequestDispather object and then forward the request object to page 2.
One suggestion.
craig.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic