【转】HttpServletRequest.getParameter() &HttpServletRequest.getAttribute() 区别
Ref:
HttpServletRequest的getParameter和getAttribute方法有什么区别
具体如下几点:
(1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法
(2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter()方法来获得请求参数。
例如假定welcome.jsp和authenticate.jsp之间为链接关系,welcome.jsp中有以下代码: <a href="authenticate.jsp? username=weiqin"authenticate.jsp </a或者:<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"); %>
(3)当两个Web组件之间为转发关系时,转发目标组件通过getAttribute()方法来和转发源组件共享request范围内的数据。假定 authenticate.jsp和hello.jsp之间为转发关系。authenticate.jsp希望向hello.jsp传递当前的用户名 request.setAttribute("username",username);%<jsp:forward page="hello.jsp" / 在hello.jsp中通过getAttribute()方法获得用户名字: <% String username=(String)request.getAttribute("username"); % Hello: <%=username %>
从更深的层次考虑,request.getParameter()方法传递的数据,会从Web客户端传到Web服务器端,代表HTTP请求数据。request.getParameter()方法返回String类型的数据。 request.setAttribute()和getAttribute()方法传递的数据只会存在于Web容器内部,在具有转发关系的Web组件之间共享。这两个方法能够设置Object类型的共享数据。 request.getParameter()取得是通过容器的实现来取得通过类似post,get等方式传入的数据,, request.setAttribute()和getAttribute()只是在web容器内部流转,仅仅是请求处理阶段。
getAttribute是返回对象,getParameter返回字符串
【转】HttpServletRequest.getParameter() &HttpServletRequest.getAttribute() 区别的更多相关文章
- JSP中getParameter和getAttribute区别
(1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter ...
- getParameter和getAttribute区别
(1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter ...
- request:getParameter和getAttribute区别
getParameter 是用来接受用post个get方法传递过来的参数的.getAttribute 必须先setAttribute.(1)request.getParameter() 取得是通过容器 ...
- request中getParameter和getAttribute的区别
整理一下getParameter和getAttribute的区别和各自的使用范围. (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方 ...
- Request的getParameter和getAttribute方法的区别
下面整理一下getParameter和getAttribute的区别和各自的使用范围. (1)HttpServletRequest类有setAttribute()方法,而没有setParam ...
- request.setAttribute和request.getAttribute还有session.setAttribute和session.getAttribute还有request.getParameter和request.getAttribute区别和联系
1.session.setAttribute()和session.getAttribute()配对使用,作用域是整个会话期间,在所有的页面都使用这些数据的时候使用. 2.request.setAttr ...
- 解决httpServletRequest.getParameter获取不到参数
用httpServletRequest.getParameter接收post请求参数,发送端content Type必须设置为application/x-www-form-urlencoded:否则会 ...
- HttpServletRequest和ServletRequest的区别.RP
问题: 请问HttpServletRequest和ServletRequest的区别? 回答: servlet理论上可以处理多种形式的请求响应形式 http只是其中之一 所以HttpServletRe ...
- getParameter和getAttribute有什么区别
1.getAttribute是取得jsp中 用setAttribute設定的attribute 2.parameter得到的是string:attribute得到的是object 3.request. ...
随机推荐
- IIS 之 托管管道模式
IIS 7.0 支持两种管道模式: (1)IIS 7.0 最新提供的集成管道模式(Integrated), (2)经典管道模式(Classic),经典管道模式是由先前版本的IIS提供的. 我们可以通过 ...
- 顺丰接口 api对接说明
1 功能说明 物流轨迹查询-使用的物流单号和快递单号即可实现查询物流信息. 1.1 接口规则 (1).查询接口支持按照运单号查询(单个查询). (2).指定的物流运单号选择相应的快递公 ...
- PathAnimation
使用Blend制作PathAnimation 1:选中Path转换为运动路径 2:选择目标对象 PathAnimation使用动态的Path PathAnimation动画在播放的时候,PahtGeo ...
- js正则表达式验证账号手机号电话邮箱
1.账号 规则:字母.数字.下划线组成,字母开头,4-16位. 表达式:/^[a-zA-z]\w{3,15}$/: 2.手机号 规则:11位数字,以1开头 表达式:/^1\d{10}$/ 3.电话号码 ...
- 【Android Studio使用教程6】Execution failed for task ':×××:compileReleaseAidl'
使用Android Studio运行项目时候,经常会报一些错,比如 Execution failed for task ':×××:processReleaseResources' Execution ...
- DPKG命令与软件安装、APT
====Linux软件包==== Linux系统中,软件通常以源代码或者预编译包的形式提供. 软件的源代码通常需要编译为二进制代码才可使用,安装比较耗时.用户可以自行调节编译选项,决定需要的功能或组件 ...
- Spring-boot & spring.security
spring.security提供了一种身份认证框架,开发者可以在这个框架中实现各种方式的用户身份管理,比如:LDAP.MYSQL.OAUTH.Mongo等等. spring.security认证步骤 ...
- html 中根据后台参数显示 相应的样式 EL表达式
<li><a class="${return_product_statu==-1||return_product_statu==null?'switch_xz':'none ...
- 【MongoDB】MongoDB服务器搭建(Unix/Linux)
1.安装MongboDB安装包(开源免费的哟) 在Mac 下 brew install mongoDB 就可以啦 安装要等一会儿,大概200M 2. cd到MongboDB文件夹 - 如果是用home ...
- Mindjet MindManager 2016/2017 折腾记录
https://community.mindjet.com/mindjet/topics/ensure-2017-64-bit-version-installation Mindmanager sho ...