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

时间:2021-05-26

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>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章