各位大佬,我的中文显示不了啊!!!!!!救我! byte[] tmprb=rcontent.getBytes("GB2312")|| byte[] tmprb=rcontent.getBytes("gb2312") 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 应该转换为8859_1码例如:String rcontent=ddd.getString("content").getBytes("8859_1"); String rcontent=ddd.getString("content").getBytes("8859_1"); 问题解决正确为:<%@ page contentType="text/html;charset=gb2312" %><%@ page import="java.sql.*" %><%@ page import="java.util.*" %><html><head><meta http-equiv=Content-Type content="text/html; charset=gb2312"><title>显示文章列表1</title></head><body><%//加载数据库驱动Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();//建立联接String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=swpt";String user="dike103";String password="852300";Connection aaa=DriverManager.getConnection(url,user,password);//建立数据库操作对象Statement bbb=aaa.createStatement();//获得IDString id3=(String)session.getValue("rid");String content2=request.getParameter("content2");//byte[] tmpr=content2.getBytes("GB2312");//content2=new String(tmpr);//content2= new String(content2.getBytes("ISO-8859-1"),"gb2312");java.util.Date m_date=new java.util.Date();String posttime=m_date.toLocaleString();byte[] tmpbyte=content2.getBytes("ISO8859_1");content2=new String(tmpbyte);//写入数据库String sqlq="INSERT INTO content1(content,posttime,reid) VALUES ('"+content2+"','"+posttime+"','"+id3+"')";bbb.executeUpdate(sqlq);//从数据库获得数据String sqla="SELECT * FROM content1 where id='"+id3+"'";//数据库读出结果集ResultSet ccc=bbb.executeQuery(sqla);ccc.next();String content=ccc.getString("content");tmpbyte=content.getBytes("GB2312");content=new String(tmpbyte);%><table><tr><td><%=content%></td></tr></table><%String sqle="SELECT*FROM content1 where reid='"+id3+"'";ResultSet ddd=bbb.executeQuery(sqle);while(ddd.next()) { String rcontent=ddd.getString("content"); tmpbyte=rcontent.getBytes("GB2312"); rcontent=new String(tmpbyte); //rcontent= new String(rcontent.getBytes("ISO-8859-1"),"gb2312"); %> <table><tr><td>回复:</td></tr> <tr><td><%=rcontent%></td></tr> </table> <% }%><form action=show3.jsp method=post name=lform><table><tr><td><textarea rows="14" name="content2" cols="74"></textarea></td></tr><tr><td><input type="submit" name=submit value="回复本帖"><input type="reset" name="reset" value="重写"></td></tr></table></form><%ddd.close();ccc.close();bbb.close();aaa.close();%></body></html> 你写的是什么程序呀,是自用的DEMO吗?要是这样的话就没什么了,要不是,你的SQL应该改一改,什么情况下也不可以用select * from tableName因为这样会大大降底你的查询,在SQL的语法中有介绍 用用这个,马上可以解决。<%@ page contentType= "text/html;charset=gb2312" %><% request.setCharacterEncoding("gb2312");%> 在jsp的数据库操作中,经常出现输入的是中文,但在数据库中 却变成了乱码,这是由于java虚拟机的规范中要求虚拟机内部必须实现iso8859,unicode,UTF-8三种,其他的不作要求,jdk中的虚拟机就是这样,作为一个实验用服务器,Resin对内码转换功能没有提供,致使在页面中无法正确显示中文。解决方法:编写一个字符转换函数,对输入的中文进行转换,函数如下:public String getStr(String str){try{String temp_p=str;byte[] temp_t=temp_p.getBytes("ISO8859-1"); String temp=new String(temp_t); return temp;}catch(Exception e){}return "null";} wml 2 或wml 1 的jsp中能像普通的jsp一样写纯java代码吗? 神码 面试题 关于 HTML href="#"的问题 JAVA+CORBA web.xml 载入dtd的问题 在firefox 下怎样给父窗口的text赋值 浮点数转换问题 大侠们帮帮忙,能不能帮我传一份weblogic使用datasource的javabean 出现“=?GB2312?Q?Fw: =B9=A4=D7=F7=C8=D5=BC=C7 =B3=C2=BB=D4 2003.07.18?=”乱码, 一定给分! “!”的区别,为什么在刷新时不同? 怎么控制表单的提交
例如:
String rcontent=ddd.getString("content").getBytes("8859_1");
正确为:
<%@ page contentType="text/html;charset=gb2312" %><%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<title>显示文章列表1</title>
</head>
<body>
<%
//加载数据库驱动
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
//建立联接
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=swpt";
String user="dike103";
String password="852300";
Connection aaa=DriverManager.getConnection(url,user,password);
//建立数据库操作对象
Statement bbb=aaa.createStatement();
//获得ID
String id3=(String)session.getValue("rid");
String content2=request.getParameter("content2");
//byte[] tmpr=content2.getBytes("GB2312");
//content2=new String(tmpr);
//content2= new String(content2.getBytes("ISO-8859-1"),"gb2312");
java.util.Date m_date=new java.util.Date();
String posttime=m_date.toLocaleString();
byte[] tmpbyte=content2.getBytes("ISO8859_1");
content2=new String(tmpbyte);
//写入数据库
String sqlq="INSERT INTO content1(content,posttime,reid) VALUES ('"+content2+"','"+posttime+"','"+id3+"')";
bbb.executeUpdate(sqlq);
//从数据库获得数据
String sqla="SELECT * FROM content1 where id='"+id3+"'";
//数据库读出结果集
ResultSet ccc=bbb.executeQuery(sqla);
ccc.next();
String content=ccc.getString("content");
tmpbyte=content.getBytes("GB2312");
content=new String(tmpbyte);
%>
<table>
<tr><td><%=content%></td></tr>
</table>
<%
String sqle="SELECT*FROM content1 where reid='"+id3+"'";
ResultSet ddd=bbb.executeQuery(sqle);
while(ddd.next())
{
String rcontent=ddd.getString("content");
tmpbyte=rcontent.getBytes("GB2312");
rcontent=new String(tmpbyte);
//rcontent= new String(rcontent.getBytes("ISO-8859-1"),"gb2312"); %>
<table><tr><td>回复:</td></tr>
<tr><td><%=rcontent%></td></tr>
</table>
<%
}
%>
<form action=show3.jsp method=post name=lform>
<table>
<tr><td><textarea rows="14" name="content2" cols="74"></textarea></td></tr>
<tr><td><input type="submit" name=submit value="回复本帖"><input type="reset" name="reset" value="重写"></td></tr>
</table>
</form>
<%
ddd.close();
ccc.close();
bbb.close();
aaa.close();%>
</body>
</html>
要是这样的话就没什么了,要不是,你的SQL应该改一改,
什么情况下也不可以用select * from tableName
因为这样会大大降底你的查询,在SQL的语法中有介绍
<%@ page contentType= "text/html;charset=gb2312" %>
<% request.setCharacterEncoding("gb2312");%>
却变成了乱码,这是由于java虚拟机的规范中要求虚拟机内部必须实现iso8859,unicode,UT
F-8三种,其他的不作要求,jdk中的虚拟机就是这样,作为一个实验用服务器,Resin对内码转
换功能没有提供,致使在页面中无法正确显示中文。解决方法:编写一个字符转换函数,对输
入的中文进行转换,函数如下:
public String getStr(String str)
{try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e)
{
}
return "null";
}