request.getParameter()方法傳遞的數據,會從Web客戶端傳到Web服務器端,代表HTTP請求數據。request.getParameter()方法返回String類型的數據。
<%@ page import="java.util.*" %>
<%
String title = "HttpServletRequest Method Values";
Map entries = new TreeMap();
entries.put("getCharacterEncoding", request.getCharacterEncoding());
entries.put("getContentLength", "" + request.getContentLength());
entries.put("getContentType", request.getContentType());
entries.put("getLocale", request.getLocale());
entries.put("getProtocol", request.getProtocol());
entries.put("getRemoteAddr", request.getRemoteAddr());
entries.put("getRemoteHost", request.getRemoteHost());
entries.put("getScheme", request.getScheme());
entries.put("getServerName", request.getServerName());
entries.put("getServerPort", "" + request.getServerPort());
entries.put("isSecure", "" + request.isSecure());
request.setAttribute("_table_title", title);
request.setAttribute("_table_entries", entries);
out.println(request.getCharacterEncoding());
%>
request.getParameter()取得是通過容器的實現來取得通過類似post,get等方式傳入的數據
<H1> Request Information </H1>
JSP request method: <%= request.getMethod() %>
<BR>
URL for the request: <%= request.getRequestURI() %>
<BR>
Protocol of the request: <%= request.getProtocol() %>
<BR>
Server name: <%= request.getServerName() %>
<BR>
Path: <%= request.getServletPath() %>
<BR>
Server port: <%= request.getServerPort() %>
<BR>
Remote address: <%= request.getRemoteAddr() %>
<BR>
Remote host: <%= request.getRemoteHost() %>
<BR>
Locale: <%= request.getLocale() %>
<BR>
User agent: <%= request.getHeader("User-Agent") %>
來自get 數據
<html>
<head>
<title>Retrieving the Original URI</title>
</head>
<body>
<pre>
In ShowPath1.jsp教程:request.getRequestURI() =
<%= request.getRequestURI() %>request.getServletPath() =
<%= request.getServletPath() %></pre>
<jsp:include page="ShowPath2.jsp" flush="true"/>
</body>
</html>