Solve the problem of Web engineering garbled

Source: Internet
Author: User

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&amp& Characterencoding=utf8&zerodatetimebehavior=converttonull "," root "," 123 ");


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.