Topic: 如何解决jsp输出汉字效果不同的问题

  Print this page

1.如何解决jsp输出汉字效果不同的问题 Copy to clipboard
Posted by: deepblue1979
Posted on: 2003-03-05 21:35

我用request.getParameter()方法取得参数后
在jsp文件中输出时未能正常输出汉字,而在jsp文件中
其它的汉字却可以正常输出汉字,不知为什么,
请各位大虾指教。

我在ie 的地址栏里输入
http://127.0.0.1:8080/forum/helloworld.jsp?title=中国

附源代码及结果
源代码:
<%@ page import="java.util.*" %>
<%@ page contentType="text/html;charset=gb2312" %>
<%
  String title=null;
  title=(String)request.getParameter("title");
%>
<html>
<head>
  <title>jsp ----------HelloWorld---------显示时间</title>
</head>
<body>
<h1>Hello World</h1>
时间 is:
<%
Date date =new Date();
out.println(date);
%>
<br>
<%=title%><br>
时间
</body>
</html>

输出结果:
Hello World
时间 is: Fri Jan 24 07:31:11 CST 2003
???ú
时间

2.Re:如何解决jsp输出汉字效果不同的问题 [Re: deepblue1979] Copy to clipboard
Posted by: atsmile
Posted on: 2003-03-06 13:32

JAVA在网络传输中使用的编码是"ISO-8859-1",故在输出时需要进行转化,如:
String str="中文";
str=new String(str.getBytes("GB2312"),"8859_1");


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923