This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I forward a local variable to another servlet?

 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set the variable as an attribute to the request.
request.setAttribute("myVar", localVar);
 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh yes..thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic