Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

how to create session

hi,

How can I create simple session in java class and assign a value. Remember I'm not using servlet. My Servlet is making call to other class a, and class a is calling class b etc., I like to know how can I set some value in class b based on some condition. So that finaly when it comes to <servlet fwd JSP> based on session value I can display few thing to user.

thx,
PH
0
princehyderabad
Asked:
princehyderabad
4 Solutions
 
matthew016Commented:
Not sure I follow but,
from the servlet, create the sessions and pass the session object to the classes ?
0
 
princehyderabadAuthor Commented:
from the serlvet I know hwo to create.

I'm talking abt creating session in regular class
0
 
matthew016Commented:
it's not possible in a regular class,
that's why I said to create in servlet and pass to regular classes.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
princehyderabadAuthor Commented:
But thing is based on certain condition or so i want to create session value if condition is not satisfied then i dont want to create session.
0
 
matthew016Commented:
u can apss the session and
if condition is not satisfied u can do
session.invalidate();

It's not really nice code, but should work.
U can wait for comments of other experts.
0
 
suprapto45Commented:
matthew016's statement is valid and correct. You can't create session from *normal* Java class.

What you can do is to pass one flag or variable back to your Servlet from your Java class to indicate whether you need to create session or not.

Hope that helps
David
0
 
mbvvsatishCommented:
or else
you can  pass the session object it self to the method that is being called from your servlet
and set the session value in that method based on some condition.
0
 
rajaamirapuCommented:
if you are using any web /app servers, you can store the value in a properties object (java.util.Properties) and read it where ever you want.

You will have one instance of the Properties object through out the server. In this case you need not return the values as method return types.

Hope this helps
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now