简体   繁体   中英

escaping = character in java string

Iam formating my question. Sorry for this. Here is the summary of my question

in JSP I have a field

<input  maxlength="200" name="productName" >

I enter value like " cQN==ujyRMdr+Qi8dO9Xm*eRun+ner==aLTyt?aKmGI "

In Action

public String getXMLObject(HttpServletRequest request)  throws Exception
{
    URLDecoder decoder = new URLDecoder();
    String productName = decoder.decode(productLicenseKey ,"UTF-8");
    System.out.println("-->ProductNameAction---->getXMLObject--->productName -->  : "+productName);
}

Iam getting output as " cQN==ujyRMdr Qi8dO9Xm*eRun ner==aLTyt?aKmGI ". If you observe + is converting to space which I don't want.

If I won't use decoder.decode other characters are converting to the respective escape chars. But I want as it is in the Action class


code how iam and retrieving value

in JSP I have a field

I enter value like "1012990-c1e197eda0s-a1de198b0b2-819e25307de-xnXrmXWBidhksyn70rGyTHa==cQNujyRMdrQi8dO9Xm+eRunERd==aLTyt+aKmGI+KRCcRtmP5ehfR==" In Action

private String saveProductName( SWHttpServletRequest request)
             throws Exception

{
    try
    {
                String ProductName      = request.getParameter("ProductName");
                System.out.println("-->ProductAction---->saveProductName--->ProductName -->  : "+ProductName);  
    }
 }

Iam getting output as "1012990-c1e197eda0s-a1de198b0b2-819e25307de-xnXrmXWBidhksyn70rGyTHa%253D%253DcQNujyRMdrQi8dO9Xm+eRunERd%253D%253DaLTyt+aKmGI+KRCcRtmP5ehfR%253D%253D" If we use decoder except + everything is working fine

You shouldn't have to decode anything in the action. The servlet api does that for you. request.getParameter() is sufficient. The problem is that you didn't properly encode the parameter when generating the form field or URL.

If it's a form field, then it's part of HTML code, and thus must be HTML-escaped:

<input type="hidden" name="someName" value="<c:out value="${theFieldValue}"/>"/>

The struts html:hidden also takes care of html-escaping properly.

If it's a URL, then it should be url-encoded, and html-escaped:

<c:url var="theUrl" value="someUrl.do">
    <c:param name="someName" value="${theFieldValue}"/>
</c:url>
<a href="<c:out value="${theUrl}"/>">The link text</a>

If you type this value in a text field of a form, then request.getParameter() is sufficient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM