*
The moose likes Servlets and the fly likes Can I forward a local variable to another servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can I forward a local variable to another servlet?" Watch "Can I forward a local variable to another servlet?" New topic
Author

Can I forward a local variable to another servlet?

Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
If I forward or include a servlet B from servlet A,
req.getRequestDispatcher(forwardTo).forward(req, res);
req.getRequestDispatcher(includeIn).include(req, res);
besides forward the req (request) varible by user, can I forward a local/global variable declared inside Servlet A? (eg String a=test; can I forward this 'a' variable to another servlet by forward or include) ? Thanks


Thanks everyone who helped me
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 565
Set the variable as an attribute to the request.
request.setAttribute("myVar", localVar);


I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
oh yes..thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I forward a local variable to another servlet?
 
Similar Threads
problem using RequestDispatcher
Problem forwarding a request
error on page on bottom left corner
Calling getRequestDispatcher method ??
Get values from a servlet