File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes request object from session id Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "request object from session id" Watch "request object from session id" New topic

request object from session id

Shruthi Sam
Ranch Hand

Joined: Jul 09, 2008
Posts: 73

I have a method implemented which has the argument of session id. In the same method, is it possible to get the request object. The only input am having is session id. Please provide your suggestions.

Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
The HttpServletRequest has a much shorter scope than HttpSession, so even if you could get a request object from the session, how would you know if it is the one you needed unless your application or the specification implemented some mechanism to persist requst objects; which presents a whole nuther set of issues.

If you have the session id, then somewhere along the line you must have had access to th HttpServletRequest, so why not just pass it (or some other transport object) to your method and get the session id from the object from within your method? Either that or implement a method which can return what you need from the request and call if from your first method;
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

I agree with Ed Ward. If you need you can put the object inside the session and you can get it back by request.getSession().getAttribute

Why would you need the session id?

[] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Shruthi Sam
Ranch Hand

Joined: Jul 09, 2008
Posts: 73
Thank you very much Edward and Hebert.
I agree. Here's the link:
subject: request object from session id
It's not a secret anymore!