首先建立一個(gè)測試頁面:path.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標(biāo)題文檔</title>
</head>
<body>
請求服務(wù)器:
<%= request.getServerName() %><br>
使用協(xié)議:
<%= request.getProtocol() %><br>
請求方法:
<%= request.getMethod() %><br>
請求斷口號:
<%= request.getServerPort() %><br>
Context路徑:
<%= request.getContextPath() %><br>
Servlet路徑:
<%= request.getServletPath() %><br>
URI路徑:
<%= request.getRequestURI() %><br>
查詢字串:
<%= request.getQueryString() %><br>
<br>
使用者主機(jī)IP:
<%= request.getRemoteAddr() %><br>
<%= request.getRemotePort() %>
</body>
</html>
再用一下方式測試:
http://localhost:8080/WebModule1/path.jsp?name=justin&nick=caterpillar
結(jié)果為:
請求服務(wù)器: localhost
使用協(xié)議: HTTP/1.1
請求方法: GET
請求斷口號: 8080
Context路徑: /WebModule1
Servlet路徑: /path.jsp
URI路徑: /WebModule1/path.jsp
查詢字串: name=justin&nick=caterpillar
使用者主?CIP: 127.0.0.1
1490