请教:中文显示问题

stw2662 2003-08-12 10:37:54

我用tomcat做了一个页面但经过下面的处理,还是在页面上显示???,不涉及中文的地方正常.
<%!
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";
}
%>

if (rs.next())
{
logname =rs.getString("logname");(来自数据库)
......................
logname=getStr(logname);(这句没有作用嘛?)
下面在页面中显示是出现问题
...全文
40 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rabbit8 2003-08-20
  • 打赏
  • 举报
回复
<%@ page language="java" %>
<%@ page contentType="text/html; charset=GB2312" %>


<html>
<title>
如果有一天
</title>
<body>
<h1>姓名</h1>
<% request.setCharacterEncoding("gb2312"); String str = request.getParameter("name"); %>
<%= str%>
</body>
</html>

这是我的试验,按照楼主的办法果然可以,谢谢楼上的各位了,贴出来是给遇到相同问题的朋友看的!
stw2662 2003-08-13
  • 打赏
  • 举报
回复
我试了一下下面这个就成功了,估计是tomcat的问题.
request.setCharacterEncoding("gb2312");
tomiw 2003-08-13
  • 打赏
  • 举报
回复
你试试
public static String unicodeToChinese(String s){
try{
if(s==null||s.equals(""))
return "";
String newString=null;
newString=new String(s.getBytes("ISO8859_1"),"gb2312");
return newString;
}
catch(Exception e){
return s;
}
}
ciyun 2003-08-13
  • 打赏
  • 举报
回复
看看数据库里的数据是不是正常显示的
devSteven 2003-08-12
  • 打赏
  • 举报
回复
new String(strKeyword.getBytes("ISO-8859-1"),"GB2312")
试试这个

81,117

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧