JSP value JSP database garbled solution of the full set

Source: Internet
Author: User

The solution to the database garbled by the JSP value to the JSP Chinese garbled value

All the unified utf-8 used in the code

1. The place to choose the coded interface when you install MySQL select Utf-8 encoding


2 Choosing a character set collation when building a database all UTF8--UTF-8 Unicode utf8_general_ci


3 Setting the table when the character set collation is all the same as above


There's a database over here, okay?

Next is the JSP side

4 header additions for all JSP pages

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<% @page contenttype= "text/html; Charset=utf-8 "%>


5 Connecting the database Javaservlet inside

String cc= "Com.mysql.jdbc.Driver";
String server= "Jdbc:mysql://127.0.0.1:3306/test1?useunicode=true&amp;characterencoding=utf-8";
String user= "root";
String pwd= "";


6 Project Web. XML inside the head

<?xml version= "1.0" encoding= "UTF-8"?>


7. Use Tomcat's friends in the configuration server.xml inside

Head <?xml version= ' 1.0 ' encoding= ' utf-8 '?>

Then someone said configure the Tomcat configuration file Server.xml in this sentence:

<connector
port= "8080" maxhttpheadersize= "8192"
maxthreads= "minsparethreads=" maxsparethreads= "75"
Enablelookups= "false" redirectport= "8443" acceptcount= "100"
connectiontimeout= "20000" disableuploadtimeout= "true"/>
Add this sentence: uriencoding= "UTF-8"


8. Forget a project in progress also to Utf-8, right click on the project properties inside resource inside Set

I believe you will not appear garbled, haha.

If the JSP is a value JSP, you can also use the strong turn function

String name=request.getparameter ("name"), modified to

String Name=new string (Request.getparameter ("name"). GetBytes ("Iso-8859-1"), "Utf-8");

This will show the Chinese. Of course it's troublesome if too much.


Related Article

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.