【转】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返回字符串

时间: 2024-08-04 10:12:13

【转】HttpServletRequest.getParameter() &HttpServletRequest.getAttribute() 区别的相关文章

JSP中getParameter和getAttribute区别

(1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter()方法来获得请求参数, (3)当两个Web组件之间为转发关系时,转发目标组件通过getAttribute()方法来和转发源组件共享request范围内的数据. 一般通过表单和链接传递的参数使用getParameter 通过request.setAttribute("name","

getParameter和getAttribute区别

对getParameter过程,如下图: 对getAttribute过程,如下图: 两者区别: ①getParameter()获取的是客户端设置的数据. getAttribute()获取的是服务器设置的数据. ②getParameter()永远返回字符串 getAttribute()返回值是任意类型 既然parameter和attribute都是传递参数,为什么不直接使用parameter呢? ①服务器端不能通过setParameter(key, value)来添加参数,因为没有这个函数 所以如

getParameter 与 getAttribute的区别

request.getAttribute()   :是request时设置的变量的值,用request.setAttribute("name","您自己的值");来设置值,   request.getParameter() :提取发送过来的参数如:本网页http://community.csdn.net/Expert/topic/4633/4633804.xml?temp=.3488123  request.getParameter("temp"

Request的getParameter和getAttribute方法的区别

下面整理一下getParameter和getAttribute的区别和各自的使用范围.      (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法      (2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter()方法来获得请求参数,例如假定welcome.jsp和authenticate.jsp之间为链接关系,welcome.jsp中有以下代码:      <a  href="authent

【转】HttpServerRequest getParameter 和getAttribute方法区别

HttpServletRequest.getParameter("modelName"); 能取到想要的modelObject吗?经过测试之后,发现是不能的.后来想想,其他道理挺简单的,当两个Web组件之间为转发关系时,转发源会将要共享 request范围内的数据先用setAttribute将数据放入到HttpServletRequest对象中,然后转发目标通过 getAttribute方法来取得要共享的数据.而MVC中用的就是Web组件之间的转发啊!真是笨,怎么当时没有想到呢? 下面

HttpServletRequest和ServletRequest的区别.RP

问题: 请问HttpServletRequest和ServletRequest的区别? 回答: servlet理论上可以处理多种形式的请求响应形式 http只是其中之一 所以HttpServletRequest. HttpServletResponse分别是ServletRequest和ServletResponse的子类 --------------------------------------------------------------------- 参考阅读: ========== 

说说request.getParameter/setAttribute/getAttribute的区别

1.getAttribute是取得jsp中 用setAttribute設定的attribute 2.parameter得到的是string:attribute得到的是object 3.request.getParameter()方法传递的数据,会从Web客户端传到Web服务器端,代表HTTP请求数据:request.setAttribute()和getAttribute()方法传递的数据只会存在于Web容器内部,在具有转发关系的Web组件之间共享.即request.getAttribute()方

Request的getParameter和getAttribute方法的差别

HttpServletRequest.getParameter("modelName");能取到想要的modelObject吗?经过測试之后.发现是不能的. 后来想想.其它道理挺简单的,当两个Web组件之间为转发关系时,转发源会将要共享request范围内的数据先用setAttribute将数据放入到HttpServletRequest对象中,然后转发目标通过getAttribute方法来取得要共享的数据.而MVC中用的就是Web组件之间的转发啊!真是笨.怎么当时没有想到呢? 以下整理

request.getParameter() 和request.getAttribute() 区别

getParameter 是用来接受用post个get方法传递过来的参数的.getAttribute 必须先setAttribute. (1)request.getParameter() 取得是通过容器的实现来取得通过类似post,get等方式传入的数据,request.setAttribute()和getAttribute()只是在web容器内部流转,仅仅是请求处理阶段. (2)request.getParameter() 方法传递的数据,会从Web客户端传到Web服务器端,代表HTTP请求数