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

编程学习 2021-07-05 11:23www.dzhlxh.cn编程入门
这篇文章介绍了jsp地址栏传中文显示乱码解决方法,有需要的朋友可以参考一下

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>

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板