Jump to content
xisto Community
cumanji

Getting Session Info In A Normal Class

Recommended Posts

Hello, i want to get session info from a class that is not servlet (generally from in a bean). When we use servlets it is so easy to get session info by just using request.getSession() method. Is it possible to get this session info by importing a class?

We can get info about application config by using ServletConfig class. Is there a class to like ServletConfig to get info about session/application?

Share this post


Link to post
Share on other sites

Technically there is no way to get the web session from a normal java class (POJO).However if you wire your POJO into a web application using the J2EE MVCpattern or FrontController pattern.i.e JSP submits to servlet, servlet passes the HttpServletRequest Object to POJO or bean. You can access your web session, your servlet context throught the request obejct.I suggest you do some research on MVC and FrontController design patterns.

Share this post


Link to post
Share on other sites

Technically there is no way to get the web session from a normal java class (POJO).However if you wire your POJO into a web application using the J2EE MVC
pattern or FrontController pattern.i.e JSP submits to servlet, servlet passes the HttpServletRequest Object to POJO or bean. You can access your web session, your servlet context throught the request obejct.

I suggest you do some research on MVC and FrontController design patterns.


Does any one has an easy sample code to manage the session? I have done this only in php and I want to do the same with Java Server Pages.
I want to know how to create the session, how to destroy the current session and clear all variables, how to get the session id and how to read the session variables.

Thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.