public String outStr(String strValue)
{
try
{
String strBuffer=strValue;
byte[] byteBuffer=strBuffer.getBytes("ISO8859-1");
String strReturn=new String(byteBuffer,"gb2312");
return strReturn;
}
catch(Exception e)
{
return null;
}
}
{
try
{
String strBuffer=strValue;
byte[] byteBuffer=strBuffer.getBytes("ISO8859-1");
String strReturn=new String(byteBuffer,"gb2312");
return strReturn;
}
catch(Exception e)
{
return null;
}
}
你的中文问题,在将数据保存入Mysql就出现问题了。
步骤一:用过滤器
步骤二:把数据库编码方式设为utf-8(数据库支持的话,否则只能gb2312,gbk等)
步骤三:页面也设为utf-8(与数据库保持统一)
另:如果不用过滤器则要在把数据插入DB之前作转换iso8859_1-->utf-8(要存的编码),
从DB里取数据时则不再需要转换了。
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
<html>
<head>
<title>影币管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><link href="css/css.css" rel="stylesheet" type="text/css">
</head>
<body topmargin="20" leftmargin="15" bgcolor="#D6EF7E">
中文测试::::::
<%
Class.forName("org.gjt.mm.mysql.Driver");
out.println("mysql test!");
Connection conn=DriverManager.getConnection("jdbc:mysql://202.195.240.183:3306/media_45du","media_45du","45du_manage");
out.println("success");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from film limit 10");
rs.next();
out.print(rs.getString("film_id")+" "+rs.getString("film_name")+"<br>");
String strBuffer=rs.getString("film_name");
byte[] byteBuffer=strBuffer.getBytes("ISO8859-1");
String strReturn=new String(byteBuffer,"gb2312");
out.println("next:");
out.println(strReturn);out.println("中文测试");
rs.close();
stmt.close();
conn.close();
%>
<body>
</html>===========================
显示如下:========================
中文测试:::::: mysql test! success 4339 ??
next: ?? 中文测试 ===============还是乱码!resin对中文的支持应该是很好的啊,数据库中的数据用phpadmin调出来中文显示很正常不存在乱码,在原来的linux7.2下的显示也很正常啊,程序都没有做任何改动,实在是不明白!!!我用的数据库是mysql,用过滤器是不是很麻烦?