java的url有中文参数导致乱码

话不多说,直接粘代码

发送方

UrlParaCode.jsp

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<html>
  <head>
 	<title>My JSP ‘UrlParaCode.jsp‘ starting page</title>
  </head>
  <body>
  <%
  	String UrlPara="王屯屯";
   %>
   <a href="UrlParaCodeAfter.jsp?UrlPara=<%=UrlPara %>">这是一个url带有中文参数</a>
  </body>
</html>

接收方

UrlParaCodeAfter.jsp

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>

<html>
  <head>

    <title>My JSP ‘ButttonUrlParaCodeAfetr.jsp‘ starting page</title>


  </head>
  
  <body>
    <%
    	request.setCharacterEncoding("GBK");
    	response.setCharacterEncoding("GBK");
    	String UrlPara=request.getParameter("UrlPara");
    	String DecodePara = new String(UrlPara.getBytes("ISO-8859-1"), "GBK");
    	out.println("UrlPara"+UrlPara);
    	out.println("DecodePara"+DecodePara);
     %>
  </body>
</html>


java的url有中文参数导致乱码,布布扣,bubuko.com

java的url有中文参数导致乱码

上一篇:《你必须知道的495个C语言问题》笔记--标准输入输出


下一篇:java访问控制权限和C++访问控制权限的对比