Helper House (www.bkjia.com) Tutorial Development Environment: win7; mysql-5.0.51b; ObjectWeb Lomboz for JavaEE Development Version: 3.3;
The famous Chinese garbled characters appeared today when I tried to connect to the database and read data.
However, because of the lessons learned in the previous ajax process, so the UTF-8 can be set in the place where encoding, but there is also a problem.
My jsp page code is as follows:
Reference content is as follows:
<% @ Page import = "java. SQL. DriverManager" %>
<% @ Page import = "java. SQL. ResultSet" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> Hello world! </Title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
</Head>
<% @ Taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<Body>
<%
Java. SQL. Connection conn;
String strConn;
Java. SQL. Statement sqlStmt;
Java. SQL. ResultSet sqlRst;
Try
{
Class. forName ("com. mysql. jdbc. Driver"). newInstance ();
Conn = DriverManager. getConnection ("jdbc: mysql: // localhost/j2ee", "root", "admin ");
SqlStmt = conn. createStatement (ResultSet. TYPE_SCROLL_INSENSITIVE, ResultSet. CONCUR_READ_ONLY );
String sqlQuery = "select * from USER ";
SqlRst=sqlStmt.exe cuteQuery (sqlQuery );
If (sqlRst! = Null ){
%>
<Center> User Information </center>
<Table>
<Tr> <td> User ID </td> <td> User Name </td> </tr>
<%
While (sqlRst. next ()){
%>
<Tr> <td> <% = sqlRst. getString ("U_ID") %> </td> <% = sqlRst. getString ("USER_NAME") %> </td> </tr>
<%
}
}
SqlRst. close ();
SqlStmt. close ();
} Catch (java. SQL. SQLException ex)
{
Response. getWriter (). println (ex. toString ());
}
Finally
{
}
%>
</Table>
</Body>
</Html> |
I set the page encoding <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>, eclipse encoding, mysql encoding, set all to UTF-8;
The problem persists.
Add <% @ page contentType = "text/html; charset = UTF-8" language = "java" %>
Solve the problem. It is concluded that the java code on the page also needs to be set.
Is this two different from the eclipse encoding? Or does this affect the servlet encoding?