先设计一个简单的登录界面index.htm:

request对象的方法及其参数的传递<html>
request对象的方法及其参数的传递<head><title>request的使用</title></head>
request对象的方法及其参数的传递<body bgcolor="#FFFFCC">
request对象的方法及其参数的传递<center>
request对象的方法及其参数的传递<table border="1">
request对象的方法及其参数的传递
request对象的方法及其参数的传递<h1 align="center">登陆验证</h1>
request对象的方法及其参数的传递<hr>
request对象的方法及其参数的传递<form action="requestform.jsp">
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<td>用户名:</td>
request对象的方法及其参数的传递<td><input type="text" name="username" size="20"></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<td>密&nbsp;码:</td>
request对象的方法及其参数的传递<td><input type="password" name="password" size="20"></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<td align="center"><input type="submit" name="Submit" value="提交"></td>
request对象的方法及其参数的传递<td align="center"><input type="reset" name="Submit2" value="重填"></td>
request对象的方法及其参数的传递</form>
request对象的方法及其参数的传递</table>
request对象的方法及其参数的传递<hr>
request对象的方法及其参数的传递<h3>演示request对象的方法及其参数的传递</h3>
request对象的方法及其参数的传递</center>
request对象的方法及其参数的传递</body></html>

输入信息后,提交到requestform.jsp页面,该页面用来显示一些参数:

request对象的方法及其参数的传递<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*" %>
request对象的方法及其参数的传递<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
request对象的方法及其参数的传递<%
request对象的方法及其参数的传递    request.setCharacterEncoding("GBK");
request对象的方法及其参数的传递%>
request对象的方法及其参数的传递<html>
request对象的方法及其参数的传递<head><title>request对象的使用</title></head>
request对象的方法及其参数的传递<body bgcolor="#FFFFCC">
request对象的方法及其参数的传递<h3 align="center">request对象的使用</h3>
request对象的方法及其参数的传递<center>
request对象的方法及其参数的传递<table border="1" width="800">
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<td>HttpUtil.getRequestURL(request)</td>
request对象的方法及其参数的传递<td><%=HttpUtils.getRequestURL(request)%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回发送信息的方式-->
request对象的方法及其参数的传递<td>request.getMethod()</td>
request对象的方法及其参数的传递<td><%=request.getMethod()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回请求的URI字符串-->
request对象的方法及其参数的传递<td>request.getRequestURL(request)</td>  
request对象的方法及其参数的传递<td><%=request.getRequestURI()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回通信协议的方式-->
request对象的方法及其参数的传递<td>request.getProtocol()</td>
request对象的方法及其参数的传递<td><%=request.getProtocol()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回程序的相对路径和文件名称-->
request对象的方法及其参数的传递<td>request.getServletPath()</td>
request对象的方法及其参数的传递<td><%=request.getServletPath()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回程序的相对路径和文件名称-->
request对象的方法及其参数的传递<td>request.getPathInfo()</td>
request对象的方法及其参数的传递<td><%=request.getPathInfo()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回发送信息的方式-->
request对象的方法及其参数的传递<td>request.getPathTranslated()</td>
request对象的方法及其参数的传递<td><%=request.getPathTranslated()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回地址栏中后面的字符串-->
request对象的方法及其参数的传递<td>request.getQueryString()</td>
request对象的方法及其参数的传递<td><%=request.getQueryString()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回发送信息的方式-->
request对象的方法及其参数的传递<td>request.getContentType()</td>
request对象的方法及其参数的传递<td><%=request.getContentType()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回发送信息的方式-->
request对象的方法及其参数的传递<td>request.getContentLength()</td>
request对象的方法及其参数的传递<td><%=request.getContentLength()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回服务器主机名称-->
request对象的方法及其参数的传递<td>request.getServerName()</td>
request对象的方法及其参数的传递<td><%=request.getServerName()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回服务器主机连接的端口号-->
request对象的方法及其参数的传递<td>request.getServerPort()</td>
request对象的方法及其参数的传递<td><%=request.getServerPort()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回客户端用户的IP地址-->
request对象的方法及其参数的传递<td>request.getRemoteAddr()</td>
request对象的方法及其参数的传递<td><%=request.getRemoteAddr()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回返回客户端用户的主机名称-->
request对象的方法及其参数的传递<td>request.getRemoteHost()</td>
request对象的方法及其参数的传递<td><%=request.getRemoteHost()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回发送信息的方式-->
request对象的方法及其参数的传递<td>request.getAuthType()</td>
request对象的方法及其参数的传递<td><%=request.getAuthType()%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递</table>
request对象的方法及其参数的传递<h3 align="center">request.getHeaderNames()</h3>
request对象的方法及其参数的传递<table border="1" width="800">
request对象的方法及其参数的传递<%
request对象的方法及其参数的传递    Enumeration enu1=request.getHeaderNames();
request对象的方法及其参数的传递    while(enu1.hasMoreElements()){
request对象的方法及其参数的传递        String names=(String)enu1.nextElement();
request对象的方法及其参数的传递%>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回发送信息的方式-->
request对象的方法及其参数的传递<td><%=names%></td>
request对象的方法及其参数的传递<td><%=request.getHeader(names)%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<%
request对象的方法及其参数的传递    }
request对象的方法及其参数的传递%>
request对象的方法及其参数的传递</table>
request对象的方法及其参数的传递<h3 align="center">getParameterNames()</h3>
request对象的方法及其参数的传递<table border="1" width="800">
request对象的方法及其参数的传递<%
request对象的方法及其参数的传递    Enumeration enu2=request.getParameterNames();
request对象的方法及其参数的传递    while(enu2.hasMoreElements()){
request对象的方法及其参数的传递        String names=(String)enu2.nextElement();
request对象的方法及其参数的传递%>
request对象的方法及其参数的传递<tr>
request对象的方法及其参数的传递<!--返回发送信息的方式-->
request对象的方法及其参数的传递<td><%=names%></td>
request对象的方法及其参数的传递<td><%=request.getParameter(names)%></td>
request对象的方法及其参数的传递</tr>
request对象的方法及其参数的传递<%
request对象的方法及其参数的传递    }
request对象的方法及其参数的传递%>
request对象的方法及其参数的传递</table>
request对象的方法及其参数的传递</table>
request对象的方法及其参数的传递</center>
request对象的方法及其参数的传递</body></html>
request对象的方法及其参数的传递

测试request对象的方法,以及传的参数的功能:

启动Tomcat服务器,在IE地址栏中键入URL为:

http://localhost:8080/sky2098/request/index.htm

页面效果如图所示:

request对象的方法及其参数的传递

我们可以随意输入参数,也可以是空值,则提交后页面为(我输入的用户名为sky2098,密码88888888):

request对象的方法及其参数的传递

其中显示了request对象的一些方法能够实现的功能,我们可以看到各个方法的实现以及参数的传递:

 

request对象的使用

HttpUtil.getRequestURL(request) http://localhost:8080/sky2098/request/requestform.jsp
request.getMethod() GET
request.getRequestURL(request) /sky2098/request/requestform.jsp
request.getProtocol() HTTP/1.1
request.getServletPath() /request/requestform.jsp
request.getPathInfo() null
request.getPathTranslated() null
request.getQueryString() username=sky2098&password=88888888&Submit=%CC%E1%BD%BB
request.getContentType() null
request.getContentLength() -1
request.getServerName() localhost
request.getServerPort() 8080
request.getRemoteAddr() 127.0.0.1
request.getRemoteHost() 127.0.0.1
request.getAuthType() null

request.getHeaderNames()

accept */*
referer http://localhost:8080/sky2098/request/index.htm
accept-language zh-cn
ua-cpu x86
accept-encoding gzip, deflate
user-agent Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)
host localhost:8080
connection Keep-Alive
cookie JSESSIONID=81EBF4B4973D85FBCC5C0EE2774D5413

getParameterNames()

password 88888888
Submit ?á??
username sky2098

相关文章:

  • 2021-08-17
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-02
  • 2022-12-23
  • 2021-10-07
  • 2021-07-01
  • 2021-12-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案