aspose file tools*
The moose likes Servlets and the fly likes How to transfer variable values from one servlet to another? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to transfer variable values from one servlet to another?" Watch "How to transfer variable values from one servlet to another?" New topic
Author

How to transfer variable values from one servlet to another?

ramesh kumar
Ranch Hand

Joined: Nov 16, 2000
Posts: 32
Hi
My program needs to transfer variables from one servlet to another. The following html page runs a servlet and the results
were hyperlinked. when I clik the hyperlinked values it has to
open another web page and as well it has to run a servlet.
I am giving my coding here.

//the servlet program is here.


The concept of the program is to display a file, viz. text file
from the server m/c, giving the correct name. the file name has
to check first whether it is file or directory, then if it is available it has to be shown as hyperliknked. after cliking the link the browser has to either download or display the whole file content.
[I added UBB CODE tags to your source code to make it more readable. Please try to use
them in the future. Learn more about UBB codes here - Ajith ]

[This message has been edited by Ajith Kallambella (edited January 11, 2001).]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12781
    
    5
It looks to me like you could just include one or more hidden variables in your form. (incidently you left the </form> off)
<input type="hidden" name="foo" value="baz" >
Bill
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
Another choice would be to store the variables in the session object (HTTPSession) in the first servlet and retrieve them in the second servlet. Let me know if you need more details.
Also I am not sure why you are overriding the service method in your servlet. You should define the doPost method instead.
Good Luck,
Joe
rejieve alexander
Greenhorn

Joined: Dec 10, 2000
Posts: 22
Yeah ! Joe, Could u plz tell me how to pass the variables thro' HttpSessions..
Thanks
Joe Paolangeli
Ranch Hand

Joined: Apr 05, 2000
Posts: 73
I will give you some sample code but it would also be beneficial for you to review the HttpSession Object in Servlet API Documentation. Here is the sample code:
First Servlet:

Second Servlet:

Hope this helps,
Joe
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to transfer variable values from one servlet to another?