Topic: 求助~JSP乱码再现~~~~~~~大虾帮手~~

  Print this page

1.求助~JSP乱码再现~~~~~~~大虾帮手~~ Copy to clipboard
Posted by: naughty009
Posted on: 2005-08-23 21:13

demo.jsp代码如下:

<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage=""%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<title>建立session</title>
<body>
<%
request.getSession(true);
session.putValue("enter","true");
%>
<center><font color=green size=5><b>你好,欢迎你来到naughty世界</b></font>
<a href=demo1.jsp>浏览最新信息</a>
<font color=red size=4>
<%
  request.setCharacterEncoding("GBK");
  String msg=request.getParameter("msg");
  if(msg!=null)
  out.print("<br>" + msg);
%>
</center>
</body>
</html>

demo1.jsp代码如下:

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网站内页</title>
</head>

<body>
<%
  
  if((String)session.getValue("enter")!="true");
  response.sendRedirect("demo.jsp?msg=你好啊~");
%>
</body>
</html>

当运行时,“你好啊~”就变成了乱码了,英文就不会,中文就出问题了~

2.Re:求助~JSP乱码再现~~~~~~~大虾帮手~~ [Re: naughty009] Copy to clipboard
Posted by: benbon
Posted on: 2005-09-09 10:15

<%
request.setCharacterEncoding("GBK");
String msg=request.getParameter("msg");//String msg=new String(request.getParameter("msg").getByte("iso-8859-1");
if(msg!=null)
out.print("<br>" + msg);
%>
改成:String msg=new String(request.getParameter("msg").getByte("iso-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