I have a page that handles error when there's one textbox with no content. Now for example I have 3 textboxes then I only put text on the two textbox. When I submit the page an error handler like "*" will appear right beside the empty textbox before the submit procedure. But the contents of the two textboxes were gone so I need to retyped what I've type before. How to prevent this?
Asked
Active
Viewed 158 times
1 Answers
1
Just redisplay the submitted value from the request parameter map.
<input type="text" name="foo" value="${fn:escapeXml(param.foo)}" />
The JSTL fn:escapeXml()
is not mandatory for display, but it will save you from XSS attack holes.
See also:
- Our servlets wiki page - the hello world example does exactly the same, perhaps you've never seen our JSP/Servlet/JSTL/EL wiki pages, they're very useful for starters like you
- How can I retain HTML form field values in JSP after submitting form to Servlet?
- XSS prevention in JSP/Servlet web application
-
an error occured The attribute prefix fn does not correspond to any imported tag library – PeterJohn Jan 30 '13 at 15:03
-
:) Click the "JSTL" link in my answer to learn how to install/import it. Or ask a new question if you really stucks (I'd be surprised though). This is off topic to the current question. – BalusC Jan 30 '13 at 15:05
-
I solved already by placing `<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>` But how about if Im using a populated dropdown list? with this code `` – PeterJohn Jan 30 '13 at 15:09
-
how to implement this with dropdown list?It works fine with my textbox already – PeterJohn Jan 30 '13 at 15:13
-