Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Request Dispatch adding new parameters

 
Sham Jowsaki
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI all,
In Request Dispatcher method i need add one more parameter in my first servlet and then it has to forward to second servlet along with old parameter and new parameters (created in first servlet).
it is always returning null(created in first servlet).. can you pls advise me.
tks
jowsaki
 
boyet silverio
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello Sham,
I understand a jsp (where parameters were provided) was called first. The jsp then forwards to the first servlet where you want to add new "parameters" say to be retrieved in the second
servlet. Parameters can not be added in the first servlet but "attributes" can be added instead, by using e.g.
request.setAttribute("newParam", newParam); // in the first servlet before forwarding to the second
request.getRequestDispatcher("/SecondServlet").forward(request, response);
Retrieve the "attribute" in second servlet thru
String newParam = (String)request.getAttribute("newParam");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic