在输入字段中重新显示提交的值 [英] Redisplay submitted value in input field
问题描述
我在jsp页面中具有搜索功能.当用户键入"abc"并进行搜索时.我得到了结果,但是有没有办法将abc与搜索结果一起返回到该搜索文本框?谢谢.
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.
推荐答案
只需使用提交的值预填充输入值.通过输入字段名称作为键的${param}
请求参数映射,可以在EL中获得提交的输入值.
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)}" />
请注意 JSTL fn:escapeXml()
的重要性.这是为了防止您的页面 XSS
Note the importance of JSTL fn:escapeXml()
. It's to prevent your page from XSS attacks while redisplaying user-controlled input.
上面的示例将用request.getParameter("query")
的结果预填充输入值.由于 EL 是null安全的,因此如果返回null
,则不会显示任何内容.
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
.
这篇关于在输入字段中重新显示提交的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!