wood burning stoves
The moose likes Servlets and the fly likes Getting and sending variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting and sending variables" Watch "Getting and sending variables" New topic

Getting and sending variables

Chris Stewart
Ranch Hand

Joined: Sep 29, 2001
Posts: 124
I'm trying to keep the 3 Tier architecture. I'd like to have a JSP page for presentation with a value. I then pass the value of that variable to the servlet using the request.getParameter method. I perform some operations with the variable. Now when I redirect from my servlet to a new JSP, how can I get the value of that variable?
Kaustubh Patil
Ranch Hand

Joined: Aug 13, 2001
Posts: 164
Whenever u pass a form fiels as a part of request its just for the request. You can get it only in the servlet. When you invoke another jsp or servlet from it.. the values are no more part of the request.
There are two ways to get the values on the next page also..
1. put it in the session. But one should be very careful about putting anything in to session. because if the session gets too heavy it hampers the performance of the application.
2. another way is that when invoking a jsp/servlet from the servlet put the value as a hidden field or as a wuery string.
hope it helps..

Kaustubh. Mumbai, India.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Chris, instead of redirecting, you can use the forward method of the requestDispatcher. In this case the rquest object is available to the JSP.

So much trouble in the world -- Bob Marley
I agree. Here's the link: http://aspose.com/file-tools
subject: Getting and sending variables
It's not a secret anymore!