格式一:
地址栏显示格式: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>
|