How do you pass variable data from one Java Servlet to another?

Question title says it all.
I have a servlet that get data from an Oracle database.
The user can then pick a piece of data.  I want to pass
what the user picks to another servlet but can figure out
how to do it.  Any takers?
afsacAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

heyhey_Commented:
you can use HTTPSession object to attach some Java objects to the client Session or you can embed some encoded information into the generated HTML page (invisible Form Text Fields)
0
afsacAuthor Commented:
Let me try giving more information:
I have a Oracle database on a Unix machine.
I want to use Java Servlets to allow a user
to Add, Modify, and Delete records from this
table.
I have this working in a Java Applet (using jdbc)
and all works fine, except that it is very slow.
I want to show the same process using Servlets.
I have a servlet that opens the database and
retreives the "items" and displays them to
the user.  I then want the user to pick an
item and pass what they picked to another
applet that will read the database again for the
item they picked and display the rest of the record
for that item. The user will then be able to modify
the contents of the record and write it back out
to the database (using jdbc).  Like I said, this
works fine as an applet, I'm tring to speed this
project up by using servlets. I may be using the
wrong tool for the right job.......
0
slokCommented:
when your Servlet1 get data from the
database and return to the user a HTML
page, you can do the following :

1. have the data be 'print' as Hypertext
links to the Servlet2
eg.
<a href="/servlet/Servlet2?DataID=123">User Choose 2</a>

or maybe

2. the data become part of a selection
in a form field like select list,
checkbox etc.
From here, you can have the Servlet2 be
the servlet that the form will post to.

Hope this helps.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

afsacAuthor Commented:
Your suggestion (2) is what I have been using
and I have got it to work.  Please do what you
do and I will award you the points.  Thank you
for your help.

Don
0
slokCommented:
when your Servlet1 get data from the
database and return to the user a HTML
page, you can do the following :

1. have the data be 'print' as Hypertext
links to the Servlet2
eg.
<a href="/servlet/Servlet2?DataID=123">User Choose 2</a>

or maybe

2. the data become part of a selection
in a form field like select list,
checkbox etc.
From here, you can have the Servlet2 be
the servlet that the form will post to.

Hope this helps.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mbormannCommented:
Servlet collaboration is possible through three methods as given in the book 'Java Servlet Programming' by Jason Hunter.

(1)Through the System Properties list if on the same JVM.
System.getProperties().put("key","value");
You can get / remove them ,also as the Properties is a derived class from Hashtable you can trick the JVM and put ANY class against a String Key .

(2)thru a shared Object. A shared object can hold the pool of shared information and make it available to each servlet as needed.

There's 1 thing to watch out for when collaborating through a shared object,the garbage collector. It can reclaim the shared object any time if it isn't referenced by a loaded servlet. To do so ,it's wise for every servlet using a shared object to save a reference to the object.

(3)easiest is inheritance. Each servlet interested in collaboarting can extend the same class and inherit the same shared information.

This simlifies the code for the collaborating servlets and limits access to the shared info to the proper subclasses. The common superclass holds a reference to the shared info ,or it can hold the shared info itself.

If you are interested buy the excellent book or I can post code for (2) & (3) later tommorrow.
0
afsacAuthor Commented:
I have the above mentioned book by Jason Hunter.
It is very good and has helped me a lot. Thank you
for your input mbormann, I appreciate your time.
0
mbormannCommented:
Well I think that you can use the 2nd approach as outlined in the book,or the last.
:(
0
afsacAuthor Commented:
I see that it is 2:33 PST, you in Cal.?
If so, what are you doing up this time of day?
You must be dedicated!  Thanx for everything!
Don
0
mbormannCommented:
no man ,
It's 5:30 pm in afternoon here in India.
nice meeting u 2!
:(
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.