格式一:

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

1、修改Tomcat设置:

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

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

2、ahref1.jsp页面:

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

3、ahref2.jsp页面:

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.net.URLDecoder"%>
<%
String id = request.getParameter("id");
String name = request.getParameter("name");
//name = URLDecoder.decode(name, "utf-8");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
id:<%=id %>
<br/>
name:<%=name %>
</body>
</html>

格式二:

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

1、第一步同上;

2、ahref1.jsp页面:

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

3、ahref2.jsp页面:

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String id = request.getParameter("id");
String name = request.getParameter("name");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
id:<%=id %>
<br/>
name:<%=name %>
</body>
</html>
05-11 15:20