java - How to pass a request parameter from one servlet to a other while forwaring -


My goal is that I can not get it now:

I have a servlet, say 'ReportServlet' It takes a request parameter, say 'p'. I can explicitly get this parameter:

  request.getParameter ("p");  

The query string in my JSP is:

  & lt; A href = "& lt; c: url value =" / report "/>? P = value" & gt; Report & lt; / A & gt;  

And everything works fine.

Now: I have another servicelet, say 'preprocessing circle' I want to forward preprocessing services to the report services, to pass a 'P' parameter calculated in the preprocessing circle. I tried:

  requestdespect rd = getServletContext (). GetRequestDispatcher ("/ report? P =" + value); Rd.forward (request, response);  

But the parameter 'p' goes to the query string member of the request, not in the parameters.

How can I do this by using parameter parameters in the parameter? The way I can get 'P' from JSP further.

I do not want to use a request attribute because I want a unique solution to get the parameters from both a JSP and further

I think I am missing something, but what I am not able to do!

When there is a suspicion, always go on. In this situation, see

ServletContext and ServletRequest in the query 9.1.1 request dispatcher path Methods that make the RequestDispatcher objects using the code Allow the optional attachment of the query string information in the path . For example, the developer can obtain a RequestDispatcher using the following code:

  string path = "/raisins.jsp?orderno=5"; Request dispatcher rd = context.getRequestDispatcher (path); Rd.include (request, response);  

The parameters used to create the request despatcher parameter specified in the query string take precedence over other parameters of the same name given to the specified serviceletter. The parameters associated with a RequestDispatcher are only applied for the duration of the included or forwarded calls.

Then you can

  requestDirectory rd = getServletContext (). GetRequestDispatcher ("/ report? P =" + value); Rd.forward (request, response);  

and the parameter p will only be available for HttpServletRequest , which is given to the mapped resource to handle the specific path, To wit. In this case, / report> if it is a HTTPSvR , you can access it with

  request.getParameter ("p"). Can;  

Where will request will be HttpServletRequest method parameter.

When the forward (..) call termination and execution comes back to your PreProcessingServlet , the parameter now returns the local HttpServletRequest object Will not be available in


Comments