0

I want send を伴う出力となって to backend java code via http get request. My get call url is http://localhost:8080/test/getID?id=%E3%82%92%E4%BC%B4%E3%81%86%E5%87%BA%E5%8A%9B%E3%81%A8%E3%81%AA%E3%81%A3%E3%81%A6

Java code:

@RequestMapping(value = "/getCaseId")
    public ModelAndView showCaseId(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
        String msg = request.getParameter("id");
        System.out.println("URL:"+msg);
        return new ModelAndView("showID", "idList", null);
    }

Above piece of code prints URL:ãä¼´ãåºåã¨ãªã£ã¦. So what's change i need to do get the exact Japanese text what i have passed from front end.

Andy Turner
  • 137,514
  • 11
  • 162
  • 243
Santosh Hegde
  • 3,420
  • 10
  • 35
  • 51

3 Answers3

0

If you use eclipse IDE, you need to check Text File encoding. Please check with the following figure.enter image description here

Zay Ya
  • 195
  • 1
  • 4
  • 15
0

Try changing your msg line to:

String msg = new String(
    request.getParameter("id").getBytes(StandardCharsets.ISO_8859_1),
    StandardCharsets.UTF_8
);

If that will work it means that your application server (Tomcat? jetty?) is not configured correctly to handle UTF-8 in URLs.

Krzysztof Krasoń
  • 26,515
  • 16
  • 89
  • 115
  • Then this is a workaround, and the solution would be to configure Tomcat or jetty correctly. What would this solution do if it was deployed to a Tomcat or jetty that was already configured correctly? – Erwin Bolwidt Jun 13 '16 at 07:10
0

The problem is that the submitted query string is getting mutilated on the way into your server-side script, because getParameter() uses ISO-8559-1 instead of UTF-8.

So i modified my code as below and now its working

@RequestMapping(value = "/getCaseId")
    public ModelAndView showCaseId(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
        String msg = new String(request.getParameter("id").getBytes("iso-8859-1"), "UTF-8")
        System.out.println("URL:"+msg);
        return new ModelAndView("showID", "idList", null);
    }

I found this solution in http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__lxgr-hi_i_am_havi.html.

Santosh Hegde
  • 3,420
  • 10
  • 35
  • 51