欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jsp地址栏传中文显示乱码解决方法分享

程序员文章站 2023-01-03 22:33:09
test1.jsp页面: 复制代码 代码如下:<%@ page language="java" import="java.util.*" pageencoding=...

test1.jsp页面:

复制代码 代码如下:

<%@ page language="java" import="java.util.*" pageencoding="utf-8"%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
  <head>
    <title>my jsp 'test1.jsp' starting page</title>
  </head>
  <body>
    <a href="test2.jsp?name=<%=java.net.urlencoder.encode("王云鹏","utf-8") %>">test2.jsp</a>
  </body>
</html>


test2.jsp页面:

复制代码 代码如下:

<%@ page language="java" import="java.util.*" pageencoding="utf-8"%>
<%
    string name = request.getparameter("name");//get tomcat 's string formatter is iso-8859-1
    byte[] names = java.net.urlencoder.encode(name,"iso-8859-1").getbytes();//get inner tomcat 's byte content
    name = new string(names,"utf-8");//get url 's string formatter is utf-8
    name = java.net.urldecoder.decode(name,"utf-8");//decode string to chinese word
%>

<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
  <head>

    <title>my jsp 'test2.jsp' starting page</title>

  </head>

  <body>
    name:<%=name %>
  </body>
</html>