Tomcat3.1中文乱码解决办法

本文介绍在Tomcat3.1环境下配置JSP文件以正确显示中文字符的方法,并提供了一个从Oracle数据库获取数据并成功展示中文字段的例子。
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:

However, when you display resultset from Database you must add this to your Jsp
files to let them show Chinese characters as you want.

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("
");
// 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("
");
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("

转载于:http://blog.itpub.net/9650775/viewspace-922018/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值