Java Chinese internal garbled processing

Source: Internet
Author: User
Chinese in JSP, Chinese garbled often make people utterly confused. General Solutions
One, this page shows the problem
"<%@ page contenttype=" text/html;charset=gb2312 "%>"
Ii. Submission of questions
Given this problem, you can convert the read string, which is simple:
str = request.getparameter ("s");
str = new String (str.getbytes ("iso-8859-1"), "GBK");
or set
Request.setcharacterencoding ("GBK");

However, do you encounter this situation, the use of Out.println is Chinese, systemout.println is garbled, look at the following example

JSP1.JSP established

<%@ page contenttype= "text/html;charset=gb2312"%>


<title>
Mm
</title>

<body background= "" >
<form method= "POST" action= "Servlet1" >
<input type= "text" name= "MYT" size= "value =" ">
<br>
<input type= "text" name= "Myedit" size= "value =" ">
<input type= "Submit" value= "Save" name= "B5" >
</form>
</body>


-----

Servlet1 established

Package untitled2;

Import javax.servlet.*;
Import javax.servlet.http.*;
Import java.io.*;
Import java.util.*;

public class Servlet1 extends HttpServlet {

public void DoPost (HttpServletRequest request,
HttpServletResponse response) throws Servletexception, IOException
{
Response.setcontenttype ("TEXT/HTML;CHARSET=GBK");
Request.setcharacterencoding ("GBK");
PrintWriter out = Response.getwriter ();

Out.println (Request.getparameter ("Myedit"));
System.out.println (Request.getparameter ("Myedit"));

}

}

After compiling in IE run, myedit input Chinese characters, will appear I say garbled, can not underestimate, to you useful System.out.println output, I after repeated debugging, found will

<input type= "text" name= "Myt" "size=" "value =" ">" "", there is no problem. "We often use is empty, in the end what is the problem caused, I still do not know."

I have this problem with the jbuild7.0,jdevelop9.03.





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.