tomcat 中文问题

hh23 2001-07-03 12:12:34
环境是:
Redhat7.0 apache1.3.14 tomcat 3.1.1 jdk 1.3.1
1) index.jsp
<html>
<head>

<title>
test1
</title>
<head>
<body>
<%@ page contentType="text/html;charset=GBK" %>
<% String str="中文"; %>
<% byte[] by= str.getBytes("GBK");%>
<% String s= new String(by);%>
<a href="test.jsp?name=<%=str%>
">测试jsp的中文</a>
</body>
</html>

2)test.jsp



<%!String name;%>

<%

name=request.getParameter("name");
out.println(name);

%>
<%
if (name==null)
out.print("nothing");
else out.print(name);


%>
<%
out.println("汉字");
%>



结果test.jsp显示:
汉字
为什么URL中的汉字不显示?
...全文
127 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ywsws 2001-07-06
  • 打赏
  • 举报
回复
在URL中为test.jsp?name=汉字
但在jsp程序中
name=request.getParameter("name");
out.println(name);
显示为??

有谁知道是什么问题?
ywsws 2001-07-06
  • 打赏
  • 举报
回复
hh23你的问题让人有点糊涂,其实应该是:
1) index.jsp
<html>
<head>

<title>
test1
</title>
<head>
<body>
<%@ page contentType="text/html;charset=gb312" %>
<% String str="中文"; %>
<% byte[] by= str.getBytes("GBK");%>
<% String s= new String(by);%>
<a href="test.jsp?name=<%=str%>
">测试jsp的中文</a>
</body>
</html>

2)test.jsp



<%!String name;%>

<%

name=request.getParameter("name");
out.println(name);

%>
<%
if (name==null)
out.print("nothing");
else out.print(name);


%>



结果test.jsp显示:
??
为什么name的值显示为?而不是"汉字"?
ouxing 2001-07-04
  • 打赏
  • 举报
回复
对URL中的字符进行编码吧
westwood 2001-07-04
  • 打赏
  • 举报
回复
<%@ page contentType="text/html;charset=GBK" %>

不对吧,gb2312才对巴
andyrew 2001-07-04
  • 打赏
  • 举报
回复
不对,说未定义的类URLEncode.
sososo 2001-07-04
  • 打赏
  • 举报
回复
使用url编码:
<a href="test.jsp?name=<%=URLEncoder.encode(new String(str.getBytes("gb2312"),"iso8859-1"))%>

81,091

社区成员

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

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