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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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:
- XSS prevention in JSP/Servlet web application
回答2:
<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