新手请教JSP中乱码问题? ( 积分: 50 )

  • 主题发起人 主题发起人 chengang_1981
  • 开始时间 开始时间
C

chengang_1981

Unregistered / Unconfirmed
GUEST, unregistred user!
<%@ page contentType=&quot;text/html;
charset=gb2312&quot;
language=&quot;java&quot;
import=&quot;java.sql.*&quot;
errorPage=&quot;&quot;
%>
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
<title>无标题文档</title>
</head>
<%
String kn=null;
kn=&quot;陈刚&quot;;
%>
<body>
<jsp:forward page=&quot;test1.jsp&quot;
>
<jsp:param name=&quot;kn&quot;
value=&quot;<%=kn%>&quot;
/>
</jsp:forward>
</body>
</html>(第一页代码)
==================================================
<%@ page contentType=&quot;text/html;
charset=gb2312&quot;
language=&quot;java&quot;
import=&quot;java.sql.*&quot;
errorPage=&quot;&quot;
%>
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
<title>无标题文档</title>
</head>
<body>
<%String kn=request.getParameter(&quot;kn&quot;);
String result=new String(kn.getBytes(&quot;gb2312&quot;));
%>
<%=result%>
</body>
</html>(第2页代码)
===========================================
就是这两个简单页面,第一页往第二页传一个中文字符串,,然后在第2页显示,,但是却总显示乱码,,请教各位大虾这个问题如何解决?
谢谢
 
<%@ page contentType=&quot;text/html;
charset=gb2312&quot;
language=&quot;java&quot;
import=&quot;java.sql.*&quot;
errorPage=&quot;&quot;
%>
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
<title>无标题文档</title>
</head>
<%
String kn=null;
kn=&quot;陈刚&quot;;
%>
<body>
<jsp:forward page=&quot;test1.jsp&quot;
>
<jsp:param name=&quot;kn&quot;
value=&quot;<%=kn%>&quot;
/>
</jsp:forward>
</body>
</html>(第一页代码)
==================================================
<%@ page contentType=&quot;text/html;
charset=gb2312&quot;
language=&quot;java&quot;
import=&quot;java.sql.*&quot;
errorPage=&quot;&quot;
%>
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
<title>无标题文档</title>
</head>
<body>
<%String kn=request.getParameter(&quot;kn&quot;);
String result=new String(kn.getBytes(&quot;gb2312&quot;));
%>
<%=result%>
</body>
</html>(第2页代码)
===========================================
就是这两个简单页面,第一页往第二页传一个中文字符串,,然后在第2页显示,,但是却总显示乱码,,请教各位大虾这个问题如何解决?
谢谢
 
a1 = new String(request.getParameter(&quot;kn&quot;).getBytes(
&quot;iso-8859-1&quot;), &quot;GB2312&quot;);
应该是这样写
因为java 默认的传输格式iso-8859-1 得到后在转换
 
问题解决,,但是第一页也要加转化才行。
kn = new String(kn.getBytes(&quot;GB2313&quot;), &quot;ISO-8859-1&quot;);
 
后退
顶部