getting charconversion exception for “ %” value in query parameter?

空扰寡人 提交于 2019-12-13 19:16:03

问题


i am getting adding some of parameter in query string.value of these param can be "a%%","%" etc.on java code side .while parsing query parameter i m getting char conversionexception as shown below in exception log.

13:14:39,555 ERROR [STDERR] java.io.CharConversionException: EOF 13:14:39,555 ERROR [STDERR] at org.apache.tomcat.util.buf.UDecoder.convert(UDecoder.java:119) 13:14:39,555 ERROR [STDERR] at org.apache.tomcat.util.buf.UDecoder.convert(UDecoder.java:87) 13:14:39,555 ERROR [STDERR] at org.apache.tomcat.util.http.Parameters.processParameters(Paramete rs.java:428) 13:14:39,555 ERROR [STDERR] at org.apache.tomcat.util.http.Parameters.processParameters(Paramete rs.java:515) 13:14:39,555 ERROR [STDERR] at org.apache.tomcat.util.http.Parameters.handleQueryParameters(Para meters.java:298) :14:39,555 ERROR [STDERR] at org.apache.coyote.tomcat4.CoyoteRequest.parseRequestParameters(Co yoteRequest.java:1933)

what should i do?


回答1:


It sounds like the query string being sent to your Java code is malformed. The percent sign is special in query strings: It introduces a two-digit hexadecimal number identifying a character. For instance, %20 is a space. To put a percent sign in a query string correctly, one uses %25 (character 25h is the percent sign in Unicode). If the query string you're processing really, literally has %% in it, then it is malformed and you'll want to have the side sending it fixed.

Edit: In your comment you say you're the one sending the invalid query string. To properly encode a query parameter, use the encodeURIComponent JavaScript function:

var encodedValue;
encodedValue = encodeURIComponent(yourTextfield.value);
someurl = "http://example.com?x=" + encodedValue;


来源:https://stackoverflow.com/questions/1420243/getting-charconversion-exception-for-value-in-query-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!