I have a JSP page which passes the HttpServletRequest and HttpServletResponse to a Java class which dispatches the request and response to an action class based upon a parameter named “action”. The action class performs some action and sometimes forwards to another JSP where the same procedure is repeated. If your thinking I should use a servlet, your right, but that is a long story and basically I don’t have the authority too.
In one of my action classes, I validate the data and if valid, forward the request to another JSP, using the RequestDispatcher. I also tried to set the “action” attribute so that I could tell the other JSP what action to perform, however I learned that attributes are not forwarded with the request. In fact, my code started infinitely looping because I was performing the same action due to the action parameter not changing, which resulted in the request looping between action and jsp.
I found out I could override the action parameter by passing the parameter in the url of the new page. Like so:
RequestDispatcher dispatcher = request.getRequestDispatcher("someUrl.jsp?action=SOME_OTHER_ACTION");
dispatcher.forward(request, response");
This solution smells fishy to me. Can anyone provide any insight into whether this is a good idea?
I think it is one of the valid way to pass the parameters.
Other way may be, you have access to request object, you can set it as request attributes. forward is on server and you should be able to access the same request attribute on other end.