0

I have a WEB application consisting of a client (mainly AngularJS, JQuery and Bootstrap), a Servlet (TOMCAT) and a database (MySQL).

The user can enter text in a number of places (sort of free-text form). The client prepares a JSON and sends it towards the servlet who forwards to the DB, and a response JSON is returned all the way towards the client.

I found a mishandling (causing a "Character decoding failure" in the servlet) when special characters are included in the text. Specifically, I copied from MS-Word the text and pasted it into the input fields and the string included some characters that MS-Word automatically replaces (e.g. simple quote sign to a titled one - if you just type "I don't know" the ' is replaced by ) causing the error.

I tried removing control characters using myString=myString.replace(/[\x00-\x1F\x7F-\x9F]/g, "") but with no success.

Could anyone suggest what is the standard practice to properly handle this condition?

Thanks!!!

EDIT:

Here are the lines where the error is being reported (the JSON is quite large, so I'm only showing the relevant sections):

Jul 30, 2016 11:56:29 AM org.apache.tomcat.util.http.Parameters processParameters
INFO: Character decoding failed. Parameter [request] with value [{...,"Text":"I donֳ¢ֲ€ֲ™t know"..."I donֳ¢ֲ€ֲ™t know"...}] has been ignored. Note that the name and value quoted here may be corrupted due to the failed decoding. Use debug level logging to see the original, non-corrupted values.
 Note: further occurrences of Parameter errors will be logged at DEBUG level.
FDavidov
  • 3,505
  • 6
  • 23
  • 59

1 Answers1

1

Try to change the encoding of your Tomcat. You can find it in conf/server.xml, the line like this:

 <Connector port="8080" URIEncoding="UTF-8"/>
Sky
  • 7,343
  • 8
  • 31
  • 42
  • Nope. Still the same issue. I see in the catalina.out the following: `I donֳ¢ֲ€ֲ™t know` instead of `I don’t know`. – FDavidov Jul 30 '16 at 08:59
  • Try if this works for you: [http://stackoverflow.com/questions/17728077/utf-8-decoding-problems-in-java-tomcat7] – Sky Jul 30 '16 at 09:30
  • Yes!!!!! I just set `MyRequest=encodeURIComponent(MyRequest)` before sending the request towards TOMCAT (where `MyRequest` is the string version of the JSON) and that resolved the issue. Great Catch @Sky!! Thanks!!! – FDavidov Jul 30 '16 at 11:30