📄 charset.html
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<META name="description" content="Java,JDBC,EJB,Open Source,jdk,rmi">
<meta name="Keywords" content="Java, servlets, Java servlet, Javascript, ActiveX, VRML,
applet, applets, directory, news, jdbc, applications,
Java applications, Java developer, Java development, developer,
classes, Jars.com, Jars, intranet, Java applet, Javabeans,
Java products, JDK, Java development kit, java development environment, JIT,
JavaPlan, enterprise tools, JVM, Java Virtual Machine, Java resources,
SUN, CGI, Perl, database, network, html,
xml, dhtml, rating, ratings, review, jars, cgi, programming,
software review, software rating">
<title>csdn_Tomcat3.1中文乱码解决办法</title>
<style>
.news { BACKGROUND: #007cd3; font-family: "宋体"; font-size: 9pt }
.t { font-family: "宋体"; font-size: 9pt }
.t1 { color:#007cd3; font-family: "宋体"; font-size: 9pt }
.white { font-family: "宋体"; font-size: 9pt;color:#FFFFFF }
.red { font-family: "宋体"; font-size: 9pt;color:#FF0000 }
A {text-decoration: underline}
A:visited {color:#0000FF}
A:hover {color: #ff6666; text-decoration: none}
.text {font-size: 12px; line-height: 160%; font-family: "宋体"}
.text1 {color:#000000; font-size: 12px; line-height: 130%; font-family: "宋体"; text-decoration: none}
.text1:visited {color:#000000}
.text1:hover {color: #000000}
.text2 {color:#000000; font-size: 12px; line-height: 130%; font-family: "宋体"; text-decoration: none}
.text2:visited {color:#000000}
.text2:hover {color: #000000}
.text3 {font-size: 12px; line-height: 100%; font-family: "宋体"; text-decoration: none}
.large {font-size: 14.8px; line-height: 130%}
</style>
</head>
<body >
<!--start first table -->
<TR>
<TD WIDTH="20%" VALIGN="TOP">
<TR>
<TD WIDTH="20%" CLASS="t" BGCOLOR="#007cd3" align="Center"></TD>
<TR>
<TR>
<TD WIDTH="20%" CLASS="t" align="center" >
</TD>
<TR>
</td>
<TD WIDTH="100%" VALIGN="TOP" >
<TR>
<TD WIDTH="100%" CLASS="white"></TD>
<TR>
<TR>
<TD WIDTH="50%" bordercolor="#FFFFFF" CLASS="t1" bgcolor="#F0F0F0" nowrap >Tomcat3.1中文乱码解决办法
</TD>
<p> <TD WIDTH="50%" bordercolor="#FFFFFF" CLASS="t1" bgcolor="#F0F0F0" nowrap >作者:jdeveloper
</TD> </p>
<TR>
<TR>
<TD WIDTH="100%" bordercolor="#FFFFFF" CLASS="t" bgcolor="#F0F0F0" colspan=2>
<pre>
<font color=red size=+1>This is for Tomcat3.1 only</font>
I downloaded Tomcat3.1 for windows and linux and found that one must do some more work to
display Chinese characters correctly.Below is my experience:
. <font color="FFAA00">For Jsp</font>
In Jsp files, you can output Chinese characters easily,that is just do like:
<font color=blue><% out.println("北京"); %></font>
However, when you display resultset from Database you must add this to your Jsp
files to let them show Chinese characters as you want.
<p><font color=blue><%@ page import="java.sql.*" contentType="text/html;charset=GB2312" %></font>
<%
String driverName = "oracle.jdbc.driver.OracleDriver";
Driver d;
Connection con;
Statement stmt;
ResultSet results;
try {
d =
(Driver)Class.forName(driverName).newInstance();
con = DriverManager.getConnection("jdbc:oracle:thin:ndb/ndb@111.222.1.103:1521:YZB");
stmt = con.createStatement();
stmt.execute("select * from hjctest");
results = stmt.getResultSet();
StringBuffer buf = new StringBuffer();
String temp;
try {
ResultSetMetaData rsmd = results.getMetaData();
int numCols = rsmd.getColumnCount();
int i, rowcount = 0;
// get column header info
for (i=1; i <= numCols; i++){
if (i > 1) buf.append(",");
buf.append(rsmd.getColumnLabel(i));
}
buf.append("<br>");
// break it off at 100 rows max
while (results.next() && rowcount < 100){
// Loop through each column, getting the column
// data and displaying
for (i=1; i <= numCols; i++) {
if (i > 1) buf.append(",");
buf.append((results.getString(i)));
}
buf.append("<br>");
rowcount++;
}
results.close();
out.write(buf.toString());
}
catch (Exception e) {
System.out.println(e);
return;
}
con.close();
}
catch (Exception e) {
out.println("error: " + e.toString());
}
out.println("</BODY></HTML>");
%></p>
. <font color="FFAA00">For Servlet</font>
To display Chinese Characters from a servlet you should set the contentType like this
.....
<font color=blue>response.setContentType("text/html;Charset=GB2312");
ServletOutputStream out = response.getOutputStream();
out.println("北京");
</font>
...
. <font color="FFAA00">Comments</font>
Maybe, this will save you from wasting time to display Chinese characters
from Tomcat3.1 .
Good luck!
</pre>
</TD>
<TR>
</TD>
</TR>
</center>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -