I have jsp which has method action=”POST”.
Initially this jsp is called thru a Controller (Spring) with query string param1=paramValue1 in URL. (e.g /thisJsp.jsp?param1=paramValue1). Spring used GET method here so the query parameter is read.
Later I would do submit() thru javascript setting an hidden form input field $(‘#param1’).val(paramValue2).
My problem is going back to Controller, it registers that the method action is POST, but
when I do request.getParameter(“param1”), it always returns paramValue1.
Using Fiddler, I see that param1=paramValue2 is registered meaning it is set on submit().
What am I missing?
I am using Tomcat server and Spring 2.0.7
Can you see the URL that the POST is going to? Your form may or may not have its “action” property set. If it’s not set, then it will POST to the same URL that the page is currently on. This could lead to a situation where you POST to a URL with ?param1=paramValue1 in the query string, but then also has param1=paramValue2 in the post body. You could change the form so that its action is set to just “/thisJsp.jsp” without the query string, and that might solve your problem.
In general, it is valid for the same named parameter to be included more than once in a request, either a GET or a POST. You could also try calling request.getParameterValues(“param1”) in your controller, which will return an array of Strings. This will be a good test to see if you are indeed passing both values of param1.