jsp 中的汉字显示问题

hyjack 2003-08-19 12:13:41
以下是一个简单的jsp文件:
<html>
<title> 显示输入信息</title>
<body>
<%@page contentType = "text/html;charset=GB2312"%>
<%
String name= request.getParameter("name");
String sex= request.getParameter("sex");
String email=request.getParameter("email");
String address= request.getParameter("addr");
%>
<font color = "green" size="5">
<%=name%>
</font>
您好,以下是你的个人信息:<p>
性别:<%=sex%><br>
住址:<%=address%><br>
E-mail:<%=email%><br>
</body>
</html>

当我输入的是英文时,可以显示,但是输入汉字后显示的就是????,这是怎么回事啊?是不是tomcat 还有那个地方没有设置好啊 ?
...全文
64 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
goodle 2003-08-24
  • 打赏
  • 举报
回复
String name= new String(request.getParameter("name").getBytes("ISO-8859-1"),"GB2312");

转换一下就ok了
1010530 2003-08-24
  • 打赏
  • 举报
回复
同意 gwsr(咩咩)
在jsp页面加就可以了
hyjack 2003-08-24
  • 打赏
  • 举报
回复
String name= new String(request.getParameter("name").getBytes("ISO-8859-1"),"GB2312");
这样是可以显示汉字了。但是这样岂不是每条语句都要写这么长啊
有没有一条语句只在开始设置一下就行了啊?

hyjack 2003-08-24
  • 打赏
  • 举报
回复
是不是把
request.setCharaterEncoding("GBK");
加到asp语句的第一行啊
为什么会报这样的错啊:
C:\Tomcat\work\localhost\_\ch58$jsp.java:64: Method setCharaterEncoding(java.lang.String) not found in interface javax.servlet.http.HttpServletRequest.
request.setCharaterEncoding("GBK");



aku0708 2003-08-24
  • 打赏
  • 举报
回复
你定义一个METHOD
加个方法:
<%!public getStr(String str) throws Exception
{
String temp=str;
byte[] temp_p=temp.getBytes("ISO-8859-1");
return new String(temp_p,"GBK");;
}
%>
然后在插入数据库之前将有中文的变量用这个方法将变量转换一下:
String text=null;
if(request.getParameter("text")!=null&&request.getParameter("text")!="")
{
text=getStr(request.getParameter("text"));
}
shipatrioc 2003-08-24
  • 打赏
  • 举报
回复
<META http-equiv=Content-Type content="text/html; charset=gb2312">就行了
没有必要每个变量都进行编码转换,要是一个页面需要传入好多参数,显得太罗嗦了。
我们一直就是这么用的,就是 djlzxzy(紫轩竹影) 说的
在jsp的头部加上<META http-equiv=Content-Type content="text/html; charset=gb2312">就行了
whodsow 2003-08-19
  • 打赏
  • 举报
回复
在第一个getParameter前加上request.setCharaterEncoding("GBK");
就OK啦,其他什么都不用改了。
djlzxzy 2003-08-19
  • 打赏
  • 举报
回复
可能在<head></head>之间缺少这一句

<META http-equiv=Content-Type content="text/html; charset=gb2312">
gwsr 2003-08-19
  • 打赏
  • 举报
回复
在文件的最上面一行加上:request.setCharaterEncoding("GBK");
bbdeng 2003-08-19
  • 打赏
  • 举报
回复
String name= new String(request.getParameter("name").getBytes("iso-8859-1")."gb2312");
...
coffee_cn 2003-08-19
  • 打赏
  • 举报
回复
<%!
public static String getGBString(String in){
try{
String _p=in;
byte[] _t=_p.getBytes("ISO8859-1");
String _out=new String(_t);
return _out;
}
catch(Exception e){

}
return "null";
}
%>
JustBT 2003-08-19
  • 打赏
  • 举报
回复
iso得好像不行吧。应该是gb2312
黑马 2003-08-19
  • 打赏
  • 举报
回复
在web.xml 里配置CharaterEncoding就可以
dgyujingjun 2003-08-19
  • 打赏
  • 举报
回复
String name= request.getParameter("name").getbytes("ISO8859-1")

81,090

社区成员

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

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