tags:

views:

61

answers:

2

Hi I like to know is there only one way to call session using request.getSession() or is there any other way?

+2  A: 

The api shows two methods. Basically one creates the session for you if needed, and the other doesn't.

http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletRequest.html#getSession%28%29

and

http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletRequest.html#getSession%28boolean%29

Yoni
He might not be expecting this. But its fair enough. +1
Adeel Ansari
A: 

If you're thinking of something like MagicSessionSignleton.getSession(), that can be called from anywhere in the code, unfortunately there isn't. You can however, build a filter that does that for you (or use a framework that provides simple access to the request/session context).

FRotthowe