How to pass a string containing double quotes from jsp to a servlet via URL using the get method

I want to set the jsp parameter to an attribute value that can contain special characters, and then use the GETsubmit form to pass the parameter to the servlet controller. For example, the parameter:

<input type="hidden" name="searchTerms" value="${sessionScope.combTerms}"></input>

I noticed that if it sessionScope.combTermscontains double quotes, for example. location:"LOC1", the controller receives the value searchTermsonly location:in which it LOC1"will disappear. What should I do to make sure that any line in is sessionScope.combTermscorrectly passed to the controller? Thanks in advance.

+3
source share
3 answers

HTML fn:escapeXml(). HTML-, HTML- ( , ), XSS- , .

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

<input type="hidden" name="searchTerms" value="${fn:escapeXml(sessionScope.combTerms)}">

URLEncode. - . & . , - %26. - XML-, URL-. " , &#34;.

+3
<% String st = str.replaceAll("\"", "&quot;");%> ,and use st instead of str.
+1
source

Source: https://habr.com/ru/post/1757099/


All Articles