java http request garbled problem: (recommended: java video tutorial)
get request garbled code:
Solution: After obtaining the string in the background, convert the encoding, such as the common encoding ISO-8859-1, the code is as follows
String name = request.getParameter("name"); name=new String(name.getBytes("ISO-8859-1","utf-8"))
garbled characters in post request:
Solution Method: Add
response.setCharcacterEncoding("utf-8")
to the servlet page. For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of Solution to java get garbled problem. For more information, please follow other related articles on the PHP Chinese website!