Solved

how to create session

Posted on 2006-11-14
8
329 Views
Last Modified: 2010-03-31
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
Comment
Question by:princehyderabad
8 Comments
 
LVL 9

Expert Comment

by:matthew016
ID: 17940846
Not sure I follow but,
from the servlet, create the sessions and pass the session object to the classes ?
0
 

Author Comment

by:princehyderabad
ID: 17940877
from the serlvet I know hwo to create.

I'm talking abt creating session in regular class
0
 
LVL 9

Expert Comment

by:matthew016
ID: 17940912
it's not possible in a regular class,
that's why I said to create in servlet and pass to regular classes.
0
 

Author Comment

by:princehyderabad
ID: 17940964
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 9

Accepted Solution

by:
matthew016 earned 50 total points
ID: 17940991
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
 
LVL 16

Assisted Solution

by:suprapto45
suprapto45 earned 25 total points
ID: 17943727
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
 
LVL 10

Assisted Solution

by:mbvvsatish
mbvvsatish earned 25 total points
ID: 17944821
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
 
LVL 5

Assisted Solution

by:rajaamirapu
rajaamirapu earned 25 total points
ID: 17946094
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Logs to delete in Windows VCenter server ? 11 159
countHi challenge 25 84
@SBGen Method 3 25
Java - Why doesn't this JFrame work 3 16
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now