1

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Jack
  • 785
  • 4
  • 12
  • 19

2 Answers2

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
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