R
R
Rockstar182014-01-31 22:34:09
Java
Rockstar18, 2014-01-31 22:34:09

How to make a request from one servlet to another using a Russian word in the parameter value?

There are two classes inheriting HTTPServlet from one to the other I send a request using the following code

String data = URLEncoder.encode("phrase","UTF-8") + "=" + URLEncoder.encode(phrase, "UTF-8");
            data += "&" + URLEncoder.encode("id", "UTF-8") + "=" + URLEncoder.encode(userId, "UTF-8");


            URL url = new URL(SERVER_URL);
            URLConnection connect = url.openConnection();
            connect.setDoOutput(true);
            OutputStreamWriter out = new OutputStreamWriter(connect.getOutputStream());
            out.write(data);


In short: servlet1 sends a request that contains a parameter (phrase) whose value is a string of Russian letters (the second parameter does not matter, since the request passes fine and I'm sure servlet2 catches it),
while servlet2 does not recognize this text and does not performs the necessary actions with it, after which it returns back unchanged.

The question is how to make servlet2 understand servlet1 in Russian.

PS
if the parameter value consists of English letters, then everything works, so there is some kind of misunderstanding of the Russian language on the part of the servlet2 + as far as I understand, usingSystem.out.println()the Russian string in the request turns into a string of bits (2 for each letter), but at the same time, when servlet1 receives this string back, it displays it in its original form.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question