Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

storing request object in session

 
Pradeep C Nair Infosense
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was trying to store request object in session variable. but that session variable is empty on the next page. but i can access that variable in the page, where it is stored. is it not possible to store request object in session?
i was trying to access the request object in a frameset. is there anyway to pass request object to a particular frame?
 
Dhirender Kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
session.setAttribute("name",value);
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpSession session = request.getSession();
session.setAttribute("request", request);

won't work too well, you're getting recursive calls here.
HttpSession session = ((HttpRequest)session.getAttribute("request")).getSession();

Doesn't look healthy
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused. Are you attempting to store the entire request object into the session or just certain attribute-value pairs into the session?

If its the former, why not consider iterating through your request object and store them into your session?

Hope I didn't misinterprete your question.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, it's a really bad idea and I hope it doesn't work - if somehow it does, the behaviour would be indeterminate ie wierd and unpredictable.

As some pole have hinted, you're better moving the specific request-scope data to the session if you want to hold on to it, don't try to hold the request object, it represents something completely different.

Dave
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Storing the request object ANYWHERE is a bad idea. Request objects are managed by the servlet container and you MUST NOT try to hang on to one past the end of a single request. If you need to keep all the parameters try something like getParameterMap().
Bill
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic