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

被折叠的 条评论
为什么被折叠?



