In my experience, all lines should be removed from Html before being displayed on the page. Our current project is dedicated to the management of all organizational units from Active Directory, and these units can contain any special character (including an HTML character). When displayed on the page, you can get the following code to show an entry called User <Marketing>
<a href="viewDetail.do"> <%=request.getAttribute("Name");%> </a>
after displaying the page, it will become
<a href="viewDetail.do"> User <Marketing> </a>
What actually appears as the User hyperlink on the page.
However, if you avoid the Html value before submitting to the page
request.setAttribute("Name", StringEscapeUtils.escapeHtml("User <Marketing>"));
after displaying the page, it will become
<a href="viewDetail.do"> User <Marketing> </a>
which appear correctly on the JSP page
Soon you are using Html character escaping to prevent special input. If the input contains an html character, your page will not display correctly during rendering
source share