getting charconversion exception for “ %” value in

2019-08-11 10:22发布

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条回答
三岁会撩人
2楼-- · 2019-08-11 10:37

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;
查看更多
登录 后发表回答