This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes sharing data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "sharing data" Watch "sharing data" New topic

sharing data

sri jaisi

Joined: Sep 02, 2006
Posts: 23
what are all the ways through which we can share the data between servlets and jsp in a single application.
is it possible to share data between servlets in two applications.if possible how

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Rather than ask for "All the ways" (very short question requiring a very long answer), why not explain, in some detail, what it is that you're trying to do.
Then, maybe someone will suggest the best strategy for your situation.

If you're not familiar with the various 'scope' objects made available by the servlet spec, I recommend that you download the spec and give it a read.
There is a link in my signature.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Prasad Prabhu

Joined: Oct 26, 2006
Posts: 4
To share data in the same application its good use Java beans.

To share data in the different applications you can use the servletContext.
But few containers like Tomcat will restrict from you from doing this.
You can use DB to share the data, but which is constly interms of time.
I suggest you to use XML to share the data.
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
To share data in the different applications you can use the servletContext.

Web applications do not share a ServletContext even if they are running in the same JVM.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

One way to share data is with a JavaBean and the HttpSession. That's pretty much basic JSP and Servlet development. I've got a set of free tutorials and sample code/war files that demonstrate how to use the HttpSession, and share a JavaBean between a Servlet and a JSP:

Link to Kameron's site


-Cameron McKenzie
[ November 03, 2006: Message edited by: Ben Souther ]
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: sharing data
Similar Threads
mock exam question
How can i share the session between webapps?
Sharing the data bettween web applications
Data Sharing?
How to share a context (Struts and servlet)