Quantcast
Channel: Active questions tagged servlets - Stack Overflow
Viewing all articles
Browse latest Browse all 714

How to decode a string when the charset is different between client and server (without global settings)

$
0
0

I am using tomcat + jsp model1, and the encoding of the server is UTF-8.And I'm getting two requests POST x-www-form-urlencoded, GET to a specific jsp path, and I'm sending the parameters encoded in EUC-KR.

curl -X POST 'http://localhost:8080/test.jsp' --header 'Content-Type: application/x-www-form-urlencoded' -d 'name=%C0%CC%B8%A7'curl -X GET 'http://localhost:8080/test.jsp\?name=%C0%CC%B8%A7'

It would be best if I could get the client to change it to UTF-8, but that's not currently possible, so I want to make sure that EUC-KR is only handled on a specific jsp path.

You could use request.setCharacterEncoding on that jsp page, but it won't work because you already have a servlet filter registered, and you've already used it as a request.getParameter in that filter (and GET doesn't work with request.setCharacterEncoding).

So I want to try to change the parameters I get from the jsp file back to EUC-KR one by one,
I tried 2 methods below, but it doesn't work.

// first trynew String(request.getParameter("name").getBytes("UTF-8"), "EUC-KR"); // doesn't work// second tryURLDecoder.decode(URLEncoder.encode(request.getParameter("name"), "UTF-8"), "EUC-KR")

result(first and second are same result)

expected = 이름actual = 占싱몌옙

I think I'm trying this the wrong way, but what should I do to get the string decoded correctly back to UTF-8?


Viewing all articles
Browse latest Browse all 714

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>