1.servlet Jump to JSP page
The JSP involves using a servlet to do some logical processing after the page jumps, such as Request.getrequestdispatcher ("index.jsp") in the servlet. Forward (Request, Response); Such jumps but sometimes we will encounter in the jump when the problem of Chinese garbled is the same page you have done some processing after the return to this page may also encounter such a situation maybe you would say you did not ah because this is the case in your servlet there is such a statement: PrintWriter OU t = Response.getwriter (); Maybe you have set up his character sets. But the correct solution is:
in PrintWriter out = Response.getwriter (), before setting his character set , such as: Response.setcharacterencoding ("GBK"); Jump page will not appear in Chinese garbled
2.servlet upload to database garbled problem
(1) Create a string conversion class, as shown below
import java.io.UnsupportedEncodingException;
public class Stringto {
public static String CONVERTOCN ( String str)
{
byte[] BS;
String str1 = null;
try {
bs = Str.getbytes (" Iso-8859-1 ");
str1 = new String (BS, "Utf-8");
} catch (Unsupportedencodingexception e) {
//TODO auto-generated catch block
E.printstacktrace ();
}
< /span>return str1;
}
}
Then replace the Request.getparameter ("name") with a similar
STRINGTO.CONVERTOCN (Request.getparameter ("name")); Problem solving
3.jsp garbled problem (in three steps)
(1) Uniform format, I chose UTF-8.
(2) Select Window->prerences->general->workspace->other instead of UTF-8
(3) In addition JSP also want to unify the format, because I choose is UTF-8
The code looks like this
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
Manually correct the problem that has garbled in JSP
(4) Write your own filter filters
(5)
Database garbled (MySQL)
Consolidated database and Engineering coding formats
Conn=drivermanager.getconnection ("jdbc:mysql://localhost:3306/test?useunicode=true&& Characterencoding=utf8&zerodatetimebehavior=converttonull "," root "," 123 ");