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

<html>
<head><title>request的使用</title></head>
<body bgcolor="#FFFFCC">
<center>
<table border="1">

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

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

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

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

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

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

页面效果如图所示:

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

其中显示了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

request对象的方法及其参数的传递的更多相关文章

  1. 【java】值传递和引用传递---对象作为方法的参数传入属于哪种传递

    首先 这篇作为一个永久性的问题,欢迎大家讨论 其次,个人结论如下几条: ①Java有且只有一种传递,即 值传递 ②作为方法的参数传入,都是对原本的实参进行了copy ③只不过[实参]若是[基本数据类型 ...

  2. request对象多种方法封装表单数据

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, ...

  3. day65 request对象,以及方法,response对象,render,redirect

    这里的都是我们会频繁使用到的,用得多了自然就会了,我们写项目都是少不了这些用法的,所以这就把老师的博客粘过来就好了, Request对象 官方文档 属性 所有的属性应该被认为是只读的,除非另有说明. ...

  4. request对象的方法

    request对象封装的是请求的数据,由服务器创建,作为实参传递给Servlet的方法,一个请求对应一个request对象,request对象可以获得请求数据. 1.获取请求行信息 (1)get提交 ...

  5. 匿名对象作为方法的参数和返回值与Random概念和基本使用

    应用场景 1. 创建匿名对象直接调用方法,没有变量名. new Scanner(System.in).nextInt(); 2. 一旦调用两次方法,就是创建了两个对象,造成浪费,请看如下代码. new ...

  6. django 修改 request 对象中的请求参数, 并重新赋值给 request 对象

    直接上代码, 实现流程看代码及注释 def your_view(self, request): method = request.method if method == "GET" ...

  7. 小程序wx.request的POST方法的参数传输服务器接收不到

    这是API里面的例子: 而实际这样,服务端拿到的是空值. 将header更改一下,application/x-www-form-urlencoded,则可以让服务器收到数据

  8. JAVA-JSP内置对象之request对象参数

    相关资料:<21天学通Java Web开发> request对象1.request对象不但可以用来设置和取得requset范围变量,还可以用来获得客户端请求参数请求的来源.表头.cooki ...

  9. scrapy之Request对象

    我们在使用scrapy框架的时候,会经常疑惑,数据流是怎么样在各个组件中间传递的.最近经常用scrapy+selenium爬取淘宝,又因为今天周五心情好,本宝宝决定梳理一下这方面知识. scrapy中 ...

随机推荐

  1. Http 压测工具 wrk 基本使用

    Http 压测工具 wrk 基本使用 Intro wrk 是一款现代HTTP基准测试工具,能够在单个多核CPU上运行时产生显着负载.它将多线程设计与可扩展事件通知系统(如epoll和kqueue)结合 ...

  2. Docker创建JIRA 7.2.4中文破解版

    目录 目录 1.介绍 1.1.什么是JIRA? 2.JIRA的官网在哪里? 3.如何下载安装? 4.对JIRA进行配置 4.1.打开浏览器:http://localhost:20012 4.2.JIR ...

  3. spring学习总结——高级装配学习四(运行时:值注入、spring表达式)

    前言: 当讨论依赖注入的时候,我们通常所讨论的是将一个bean引用注入到另一个bean的属性或构造器参数中.bean装配的另外一个方面指的是将一个值注入到bean的属性或者构造器参数中.在没有学习使用 ...

  4. SQLServer之修改标量值函数

    修改标量值函数注意事项 更改先前通过执行 CREATE FUNCTION 语句创建的现有 Transact-SQL 或 CLR 函数,但不更改权限,也不影响任何相关的函数.存储过程或触发器. 不能用 ...

  5. C#事件与委托详解【精华 多看看】

    Delegate delegate是C#中的一种类型,它实际上是一个能够持有对某个方法的引用的类.与其它的类不同,delegate类能够拥有一个签名(signature),并且它"只能持有与 ...

  6. BCP SQL导出EXCEL常见问题及解决方法;数据导出存储过程

    一.‘xp_cmdshell’的启用 SQL Server阻止了对组件‘xp_cmdshell’的过程‘sys.xp_cmdshell’的访问.因为此组件已作为此服务嚣安全配置的一部分而被关 闭.系统 ...

  7. macOS 安装 Java (Homebrew)

    macOS 安装多个 Java 版本 Homebrew 是 macOS 下的一个非常好用的包管理工具, caskroom 则是基于 Homebrew 构建的一个强大的应用程序管理器. Homebrew ...

  8. iOS Accessibility指南

    开发者经常会为用户开发一些令人充满惊喜的App.但是,开发者真的为每一个潜在的用户都做适配了么?是否每个人都可以真正使用你的APP呢? 设计APP.产品或者任何类型的服务,都要考虑到所有用户,包括视力 ...

  9. .NET Core跨平台部署

    目录 .NET Core跨平台部署 1. Windows-IIS 1.1 安装.NET Core Windows Server Hosting 1.2 配置应用程序池 1.3 使用发布文件 2 Lin ...

  10. 【转】Android辅助功能AccessibilityService自动全选择文字粘贴模拟输入

    网上找了很久AccessibilityService全选文字的方法,一直没找到,自己研究了半天,分享出来. /** * 输入文本 */ public void inputText(List<St ...