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

格式一:

地址栏显示格式:http://localhost:8081/Jsp2/ahref2.jsp?id=32&name=%E7%8E%8B%E4%BA%91%E9%B9%8F

1、修改Tomcat设置:

修改Tomcat目录/conf/server.xml文件:

1 <Connector port="8081" protocol="HTTP/1.1" 
2                connectionTimeout="20000" 
3                redirectPort="8443" URIEncoding="utf-8"/>

2、ahref1.jsp页面:

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%@ page import="java.net.URLEncoder"%>
 3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 4 <html>
 5   <head>
 6   </head>
 7   <body>
 8     <a href="ahref2.jsp?id=32&name=<%=URLEncoder.encode("王云鹏","utf-8") %>">ahref2</a>
 9   </body>
10 </html>

3、ahref2.jsp页面:

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%@ page import="java.net.URLDecoder"%>
 3 <%
 4     String id = request.getParameter("id");
 5     String name = request.getParameter("name");
 6     //name = URLDecoder.decode(name, "utf-8");
 7 %>
 8 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 9 <html>
10   <head>
11   </head>
12   <body>
13     id:<%=id %>
14     <br/>
15     name:<%=name %>
16   </body>
17 </html>

格式二:

如果地址栏显示格式:http://localhost:8081/Jsp2/ahref2.jsp?id=32&name=王云鹏

1、第一步同上;

2、ahref1.jsp页面:

1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
3 <html>
4   <head>
5   </head>
6   <body>
7     <a href="ahref2.jsp?id=32&name=王云鹏">ahref2</a>
8   </body>
9 </html>

3、ahref2.jsp页面:

 1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
 2 <%
 3     String id = request.getParameter("id");
 4     String name = request.getParameter("name");
 5 %>
 6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 7 <html>
 8   <head>
 9   </head>
10   <body>
11     id:<%=id %>
12     <br/>
13     name:<%=name %>
14   </body>
15 </html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值