This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Servlets and the fly likes Request Dispatch adding new parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Request Dispatch adding new parameters" Watch "Request Dispatch adding new parameters" New topic

Request Dispatch adding new parameters

Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
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.
boyet silverio
Ranch Hand

Joined: Aug 28, 2002
Posts: 173
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");
I agree. Here's the link:
subject: Request Dispatch adding new parameters