I am having trouble in maintaining the value of the query params which was sent in URL and lost during input forward due to validation error.
I have a link link this
<a href="/somelink/testpage?param1=value1¶m2=value2" id="test">Test</a>
Clicking this link opens a new page which has a form with two hidden fields (which takes the value from these params). This page has two buttons save and cancel . My problem is
I click the link, the input page corresponding to this action is test.jsp
. This renders the page.(ex the URL is https:host/somelink/testpage?param1=value1¶m2=value2
).
I fill the form and click Save button which submits the form. In the Action class I get the params and set in request and do validation . Due to validation error, control goes to input page (but without query params in url). Now the input page has the error message and the URL is https:host/somelink/testpage
Now in the test.jsp
, from the request the hidden fields in form are filled.
The error is shown in the input page. Now if I click the save button again control goes to the Action class with form being submitted. In this case I can access those params (as form is submitted)
But there is a case where in the input page with error, if the user presses Enter from address bar the request will go to action class (Remember when forward was done to the input page, the query params are not set in url, so now if request is sent there is no way to get the value of the param as its not in url and the form is not submitted.)
Is there any way I can maintain the value of the params? I am not able to append it to URL as its a input forward. Only way I found to retain the values of params is add in session and get from session. But I am not sure if its advisable.
When you submit the form you didn't pass parameters in the url. To make it working you should include parameters in the action
attribute of the form tag.
Like
<html:form action="/somelink/testpage?param1=value1¶m2=value2">
or submit the form without parameters in the URL, but to pass parameters you need to add html:hidden
fields to the form, that will hold the values.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.