R
R
reset372014-11-27 12:59:16
JavaScript
reset37, 2014-11-27 12:59:16

Incorrect encoding when passing a GET request from JavaScript to Java, what should I do?

There is a script on the HTML page:

<script type="text/javascript" charset="utf-8">
function onClick(form) {
  var largePath = $('#popupDiv .dinamic').attr("src");
  var fileName = largePath.substr(largePath.lastIndexOf('/')+1);
  
  $.get(
      "setComment",
      {
        file_name : fileName,
        comment : form.comment.value
      },
      onSuccess()
    );
...
}

This code sends a request to the server with a filename and a comment.
On the server, this request is processed like this:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
    String fileName = request.getParameter("file_name");
    String comment = request.getParameter("comment");
...

The problem is that when passing the comment parameter in Russian, the server receives a string in the wrong encoding (instead of characters: '?').
How can this be fixed? Tried using URLCode, URLDecodec - didn't help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Pavlov, 2014-11-27
@gurinderu

Well, first of all, why are you passing comment in the get request? Pass these parameters through the post.
Second replace URIEncoding="UTF-8" in server.xml for Connector

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question