How can I retain HTML form field values in JSP after submitting form to Servlet?

前端 未结 2 1419
北荒
北荒 2020-11-22 06:54

After submitting data in the HTML from, a servlet adds these data to my DB and forwards a result message to a JSP page. I want to retain the initially submitted values in th

2条回答
  •  遥遥无期
    2020-11-22 07:24

    You could access single-value request parameters by ${param}.

    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
    ...
    
    
    ...
    
    
    
    ...
    
    

    Do note that JSTL's fn:escapeXml() is necessary in order to prevent XSS attacks. See also XSS prevention in JSP/Servlet web application.

    You could access multi-value request parameters by ${paramValues} and EL 3.0 streams.

    v == 'a').get() ? 'checked' : ''} />
    v == 'b').get() ? 'checked' : ''} />
    v == 'c').get() ? 'checked' : ''} />
    ...
    
    

提交回复
热议问题