| 网站首页 | JAVA文章 | AppServers | Web开发 | 应用开发 | 资源下载 | 论坛
    想学好编程,学好英语很重要  [enadd  2006年12月25日]        
设为首页 加入收藏 联系站长
您现在的位置: 编程笔记网 >> AppServers >> TOMCAT >> 文章正文
Tomcat3.1中文乱码解决办法        【字体:
Tomcat3.1中文乱码解决办法
作者:佚名    文章来源:不详    点击数:    更新时间:2006-4-16

作者: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!

 
文章录入:enadd    责任编辑:enadd 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
  • Tomcat5的数据库连接池配置

  • Tomcat5数据源配置(转载)

  • Spring使用tomcat连接oracle…

  • 如何配置JNDI操作记实

  • Tomcat4的数据库连接池配置

  • Tomcat5的数据库连接池配置

  • Apache与Tomcat安装配置手册

  • Tomcat配置技巧Top 10

  • Jdk和Tomcat的安装与配置

  • Tomcat4.0中文问题简单解决方…

  •   网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 管理登录 |