String url = �AuthenticationServlet�; String username = request.getParameter(�username�); if (username.indexOf("something")>=0) { // I want to change the parameter // called password in request // before I forward it to the // AuthenticationServlet } ServletContext sc = getServletContext(); RequestDispatcher rd = sc.getRequestDispatcher(url); rd.forward(request, response); } Any suggestions?
Ken Pelletier
Ranch Hand
Joined: Aug 01, 2002
Posts: 54
posted
0
You ought to be able to achieve this by implementing a Filter that uses an HttpServletRequestWrapper subclass of your own. The wrapper would override the relevant getParameter* method(s) to return the value for the particular parameter(s) you're interested in "changing". I don't know whether the getParameterMap() and getParameterValues() implementations in HttpServletRequestWrapper call the underlying getParameter() method, and therefore would not need to be overridden in additon to getParameter() ( my guess is not, but you'd need to verify this ). This way, all servlets downstream in the chain will unknowingly interact with the wrapped request and get the "changed" parameter value you're wrapper returns.
ming zhu
Greenhorn
Joined: Feb 13, 2001
Posts: 16
posted
0
Ken, Thanks for the help. Do you mean I need do the following: public class newRequest extends HttpServletRequestWrapper { String getParameter(String par) { if (par.indexOf("password") == 0) { return "my_new_password"; } else { return super(par); } } } And then in the doPost method: rd.forward(newRequest, response); Thanks a lot!
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Can we change a parameter in a HttpServletRequest?