I have search functionality in my jsp page.. When user types "abc" and search for that. I get the result back but is there a way to retrieve that abc back to that search textbox along with the search results? Thank you.
Asked
Active
Viewed 525 times
2 Answers
3
Just prefill the input value with the submitted value. Submitted input values are available in EL via the ${param}
request parameter map keyed by input field names.
<input type="text" name="query" value="${fn:escapeXml(param.query)}" />
Note the importance of JSTL fn:escapeXml()
. It's to prevent your page from XSS attacks while redisplaying user-controlled input.
The above example will prefill the input value with the result of request.getParameter("query")
. As EL is null-safe, it won't display anything if it returns null
.
See also:
0
<input type="text" name="foo" value="${param.foo}" />
This will also work if you want something more basic, but I am not sure about the security

user3284391
- 15
- 2