HttpServletRequest的Attribute和Parameter区别
HttpServletRequest类既有getAttribute()方法,也由getParameter()方法,这两个方法有以下的组件通过getParameter()方法来获得请求参数,例如假定welcome.jsp和authenticate.jsp之间为链接关系,welcome.jsp中有以下代码:
<a href="authenticate.jsp username=weiqin">authenticate.jsp a>
html 代码
或者:
<form name="form1" method="post" action="authenticate.jsp">
请输入用户姓名:<input type="text" name="username"><input type="submit" name="Submit" value="提交">form>
在authenticate.jsp中通过request.getParameter("username")方法来获得请求参数
username:<% String username=request.getParameter("username"); %>
html 代码
在authenticate.jsp中通过request.getParameter("username")方法来获得请求参数username:
(3)当两个Web组件之间为转发关系时,转发目标组件通过getAttribute()方法来和转发源组件共享 request范围内的用户名字,如何传递这一数据呢?先在authenticate.jsp中调用setAttribute()方法:
在hello.jsp中通过getAttribute()方法获得用户名字:Hello:
(4)从更深的数据,会从Web客户端传到Web服务器端,代表HTTP请求数据。request.getParameter()方法返回String类型的数据只会存在于Web容器内部,在具有转发关系的共享数据。
getParameter得到的。或者是http://a.jsp id=123中的数据。
getAttribute则可以是对象。
getParameter()是获取POST/GET传递的数据值;
getParameter:用于客户端重定向时,即点击了链接或提交按扭时传值用,即用于在用表单或url重定向传值时接收数据用。
getAttribute:用于服务器端重定向时,即在sevlet中使用了forward函数,或struts中使用了mapping.findForward。getAttribute只能收到程序用setAttribute传过来的一块内存中去,当你的内存中。这样getAttribute就能取得你所设下的生命周期不一样而已。
getParameter只是应用服务器在分析你送上来的文本时,取得你设在表单或url重定向时的值
HttpServletRequest的Attribute和Parameter区别的更多相关文章
- attribute与parameter区别(转)
文章转自http://blog.csdn.net/saygoodbyetoyou/article/details/9006001 request.getParameter取得Web客户端到web服务端 ...
- Request中Attribute 和 Parameter 的区别
Attribute 和 Parameter 的区别 (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为 ...
- Attribute 和 Parameter 的区别
Attribute 和 Parameter 的区别 (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为 ...
- 参数(parameter)和属性(Attribute)的区别
参数(parameter)和属性(Attribute)的区别 区别: 来源不同: 参数(parameter)是从客户端(浏览器)中由用户提供的,若是GET方法是从URL中 提供的,若是POST方法是从 ...
- [attribute|=value]和[attribute^=value]选择器区别
1.[attribute|=value] [attribute|=value]选择器说明:http://www.w3school.com.cn/cssref/selector_attribute_va ...
- jQuery的attr与prop,attribute和property区别
jQuery1.6中新添加了一个prop方法,看起来和用起来都和attr方法一样,这两个方法有什么区别呢?这要从HTMl 的attribute与property区别说起,attr与prop正是这两个东 ...
- attribute与property区别总结
在前阵子看JQuery源码中,attr()的简单理解是调用了element.getAttribute()和element.setAttribute()方法,removeAttr()简单而言是调用ele ...
- CSS选择器[attribute | = value] 和 [attribute ^ = value]的区别
前言 首先你需要知道[attribute | = value] 和 [attribute ^ = value] 分别是什么? ①:[attribute | = value] ②:[attribute ...
- parameter与attribute的使用场合(转载自草原和大树)
Attribute 和 Parameter 的区别 (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为 ...
随机推荐
- grunt 基本使用使用(一)。
使用grunt 之前,需要做一些基本工作. 1.在E盘 新建空文件夹 grunt. 2.在grunt目录下新建package.json 文件,用了存储 npm模块的依赖项.基本依赖块代码如下: { & ...
- C# Using 用法
using 语句允许程序员指定使用资源的对象应当何时释放资源.为 using 语句提供的对象必须实现 IDisposable 接口.此接口提供了 Dispose 方法,该方法将释放此对象的资源. 一起 ...
- java.lang.OutOfMemoryError: Java heap space的解决方法
windows->preferences->Java->Installed JRES->edit->Default VM Arguments添加-Xms256m -Xmx ...
- FormatMessage与GetLastError配合使用,排查windows api调用过程中的错误
前一段时间在学习windows api调用过程中,遇到过一些调用错误或者程序没能显示预期的结果,或者直接出现vc运行时错误. 这对新手来说是司空见惯的事,因为不太熟悉难免会出错,出错的信息如果能显示很 ...
- Leetcode Elemination Game
题目网址:https://leetcode.com/contest/2/problems/elimination-game/ 题意: 给定一个从1到n的数列,第一次从最左边开始,每隔一个淘汰一个数字. ...
- mysql load file
1.MySql加载本地文件至数据库 -- 加载本地数据文件 Load Data InFile 'localfile' Into Table datatablename Fields Terminate ...
- CSS布局(二)
本节内容:position.float.clear.浮动布局例子.百分比宽度 position CSS中的position属性设置元素的位置.属性值:static.relative.fixed.abs ...
- UNIX 系统调用函数errno返回值搜集(in updating )
当Unix系统级函数遇到错误时,它们会典型地返回-1,并设置全局整数变量errno来表示什么出错了 阅读redis源码的时候,发现如果对系统级函数出错时的errno比较熟悉,写起程序来会游刃有余不少. ...
- 浅析MVC模式与三层架构的区别01
三层架构和MVC是有明显区别的,MVC应该是展现模式(三个加起来以后才是三层架构中的UI层)三层架构(3-tier application) 通常意义上的三层架构就是将整个业务应用划分为:表现层(UI ...
- 如何使cookie全站都生效?
一个页面设置的cookie, 默认在其同级目录下,及子目录下可以读取. 如果想让cookie整站有效,可以在根目录下setcookie 也可以用第4个参数,来指定cookie生效路径 setcooki ...