escape problem with tomcat

J

John Smith

I have an application that is sending an ajax request to the server and
encoding a text field into the url using escape(). If the field contains a
euro character ? escape encodes it to "%u20AC", tomcat on the server side
fails with the stack trace below. I have made sure both the request and
response are utf-8 encoded, but it does not fix it, any ideas?

Many Thanks

Jon

org.apache.tomcat.util.http.Parameters processParameters
WARNING: Parameters: Character decoding failed. Parameter skipped.

java.io.CharConversionException: isHexDigit

at org.apache.tomcat.util.buf.UDecoder.convert(Unknown Source)

at org.apache.tomcat.util.buf.UDecoder.convert(Unknown Source)

at org.apache.tomcat.util.http.Parameters.urlDecode(Unknown Source)

at org.apache.tomcat.util.http.Parameters.processParameters(Unknown
Source)

at org.apache.tomcat.util.http.Parameters.processParameters(Unknown
Source)

at
org.apache.tomcat.util.http.Parameters.handleQueryParameters(Unknown Source)

at org.apache.catalina.connector.Request.parseParameters(Unknown
Source)

at org.apache.catalina.connector.Request.getParameter(Unknown Source)

at org.apache.catalina.connector.RequestFacade.getParameter(Unknown
Source)
 
M

Martin Honnen

John said:
I have an application that is sending an ajax request to the server and
encoding a text field into the url using escape(). If the field contains a
euro character ? escape encodes it to "%u20AC", tomcat on the server side
fails with the stack trace below. I have made sure both the request and
response are utf-8 encoded, but it does not fix it, any ideas?

Don't use the escape function, use the encodeURIComponent function.
 
J

John Smith

Thanks Martin, Ive tried that the encoded form is "%E2%82%AC", this does not
cause and error in Tomcat but the string I get at the back end is not a euro
sign?

Many Thanks

Jon
 
M

Martin Honnen

John said:
Ive tried that the encoded form is "%E2%82%AC", this does not
cause and error in Tomcat but the string I get at the back end is not a euro
sign?

What do you get back exactly?

You said

so assuming Tomcat decodes as UTF-8 then it should work.

I am not familiar with Tomcat and the server side code is not really on
topic here.
Your client-side JavaScript code should do the following
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', 'process.jsp', true);
httpRequest.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
httpRequest.send('foo=' + encodeURIComponent('€'))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top