- 爱易网页
 
                        - 
                            Java教程
 
                        - JSP网页的超链接传递中文参数乱码有关问题(在IE中的有关问题) 
 
                         
                    
                    
                    日期:2014-05-17  浏览次数:20969 次 
                    
                        
                         JSP网页的超链接传递中文参数乱码问题(在IE中的问题)
出问题的情况:
在IE6中打开formtest02.jsp,先输入连续三个相同的汉字,如:啊啊啊,提交表单,中文显示正常,然后点击超链接传递中文参数,在out.jsp中显示,在out.jsp中的结果是:啊啊?(前两个汉字正常,最后一个是乱码);
如果输入连续4个相同汉字,所有显示都正常,没有乱码。
如果输入1个汉字,点链接后又是乱码。
总结:输入奇数个汉字,最后一个汉字是乱码;输入偶数个汉字,结果正常。这个问题是怎么回事?请大侠们赐教。谢谢
表单页:formtest02.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
     <base href="<%=basePath%>">
      
     <title>My JSP 'formtest02.jsp' starting page</title>
      
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">     
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
   </head>
    
   <body>
     <div align="center">表单中文处理</div>
     <form name="form1" method="post" action="<%=basePath%>/demobasics/formtest02.jsp" >
     	<input type="text" name="text1" />
     	<input type="submit" value="提交"/>
     </form>
     <br/>
     <a target="_blank" href="<%=basePath%>/demobasics/out.jsp?good=<%=request.getParameter("text1") %>">链结中文处理</a>
     <%
     	out.print(request.getParameter("text1"));
     	out.print(request.getParameter("good"));
      %>
   </body>
</html>
点超链接后的页面:out.jsp
<%@ page language="java" import="java.util.*" pageEncoding="iso-8859-1" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
     <base href="<%=basePath%>">
      
     <title>My JSP 'out.jsp' starting page</title>
      
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">     
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
   </head>
    
   <body>
     <br>
     <%
         out.println(new String(request.getParameter("good").getBytes("ISO-8859-1"),"utf-8"));
     %>
   </body>