JSPCN主页 | JSP空间 | 网站制作 | JSP下载 | JSP论坛 | JSP教程 | 关于JSPCN | 联系我们
JSP虚拟主机,jsp空间,java空间,java虚拟空间,详细请点击进入
做最专业的JSP中文网站 当前位置首页--开发工具--Tomcat  
文章搜索:
关键字 标题
  
JSP中文网内容管理系统(JCMS)
JSP虚拟主机
网络笔记本
网摘,图片,笔记收藏
虚拟服务器

JSPCN文章目录分类
JSP配置[219]JSP基础[136]
中文问题[69]上传问题[27]
JAVABEAN[46]数据库[212]
文件操作[126]图片声音[17]
JSP其他[57]时间相关[16]
JAVAMAIL[72]STRUTS[144]
开发工具[28]教程系列[157]
JSP实例[89]
JAVA基础[421]APPLET[78]
JAVA网络[179]Applica[115]
Servlet[98]XML[163]
J2ME[257]J2EE[374]
考试相关[63]JAVA线程[90]
EJB[261]Swing[26]
Java API[141]声音图片[28]
异常处理[33]JAVA实例[290]
JAVA类[139]SUN[89]
Hibernate[6]JMX[8]
Spring[34]
本版推荐文章 
本版热点文章 
相关文章链接 
 
Tomcat3.1中文乱码解决办法
作者:未知     文章来源:www.jspcn.net
访问次数:641次     加入时间:2005年01月19日
作者:jdeveloper

This is for Tomcat3.1 only
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:
. For Jsp
In Jsp files, you can output Chinese characters easily,that is just do like:
<% out.println("北京"); %>
However, when you display resultset from Database you must add this to your Jsp
files to let them show Chinese characters as you want.
<%@ page import="java.sql.*" contentType="text/html;charset=GB2312" %>
<%
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>");
%>
. For Servlet
To display Chinese Characters from a servlet you should set the contentType like this
.....
response.setContentType("text/html;Charset=GB2312");
ServletOutputStream out = response.getOutputStream();
out.println("北京");

...
. Comments
Maybe, this will save you from wasting time to display Chinese characters
from Tomcat3.1 .
Good luck!

 
JSP虚拟主机 | JSP空间 | JSP主机 | JSP双线虚拟主机 | JAVA空间 | JAVA虚拟主机 | 虚拟服务器 | JSP 虚拟服务器 | VPS
Virtual Private Server | JAVA虚拟服务器 | VM服务器 | VHOST | 虚拟操作系统 | JSP论坛 | JAVA论坛 | JSP站点论坛
Copyright © 2002-2005 JSPCN.net. All rights reserved.
JSP中文网    备案序号:蜀ICP备05001583号
成都恒海科技发展有限公司    成都市一环路南二段6号新瑞楼三楼8号