aspose file tools*
The moose likes Servlets and the fly likes sending session object from servlt-multiple jsp's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "sending session object from servlt-multiple jsp Watch "sending session object from servlt-multiple jsp New topic
Author

sending session object from servlt-multiple jsp's

Sree Mami
Ranch Hand

Joined: Jul 13, 2006
Posts: 75
Hi all

Can anyone clarify me whether I can send a session object created in servlet to multiple JSP's as I have the same set of values required in various JSP's..

Initially I wrote entire code in a JSP page and forwarded the result to the next JSP page, but as the same set of data is required in multiple JSP's I am thinking of writing it in a servlet. Can I achieve my task like that.

Any sample code appreciated..


Thanks in advance
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Sree M,
Welcome to JavaRanch!

We're pleased to have you here with us in the Servlets forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
The first name can be an initial but not the last.

You can change it here


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

As to your question:
You don't send a session object anywhere.
You simply bind objects to it.
All of the servlets and JSPs, involved in a user's session, have access to the session object. It doesn't matter whether you use a servlet or a JSP to bind the objects to session. The results will be the same.
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
Sree,

The best practice is to put all business logic in servlets (or better yet, classes called by servlets) and not in JSPs. JSPs should be strictly presentation.

If you have data that needs to be shared by multiple JSPs in the same request, you should store the data in the Request object as an attribute.

If you have data that needs to be saved across multiple http requests, store the data as an attribute in the Session object. Yes, the Session object is accessible by all JSPs and servlets that are executing for the given user/session.
Sree Mami
Ranch Hand

Joined: Jul 13, 2006
Posts: 75
Hi Ben

Thanks for your clarifications on using terminology.. I stand correct it..

Sree Mami
Ranch Hand

Joined: Jul 13, 2006
Posts: 75
Hi Scott

Really pleased to see your comments on my query. Now I am a bit clear about using "session" object in JSP/Servlet's. Actually I am very poor at servlet's so I worked with JSP's most of the time. Recently I started off working using Bean classes where I am doing all backend data processing, where I actually faced the problem of sharing the same backend information among multiple JSP's. Here I am writing individual JSP's (I will call them intermediate files to store data from backend in arraylist) for every HTTP request and binding the corresponding values to a session object which I am again forwarding to my Main JSP Form using <jsp:forward> tag. I need some of those values again in my 2nd form where I felt need of writing the same individual JSP's and I am forwarding to my 2nd form again using <jsp:forward> tag.

After seeing the redundancy in files I felt that Servlet's would suit my need to avoid duplication.

Can you refer me any good site where I can have some valuable information about Servlet's along with some examples to better understand the concepts of Servlets.


Again thanking you for giving me such a valuable information.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Perhaps this article in the JavaRanch Journal might help with understanding the patterns used in web applications.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sree Mami
Ranch Hand

Joined: Jul 13, 2006
Posts: 75
Please give me any link where I can learn Servlets and jsp's effectively
 
Don't get me started about those stupid light bulbs.
 
subject: sending session object from servlt-multiple jsp's