【转】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. ...
随机推荐
- javascript冷知识
本人很少写博客,所以文笔很不好,如果解释的不够清楚的,欢迎点评 1.+号(一元加操作符): 如果放在数值前的话,对数值不会产生任何影响,不过放在其他的数据类型前面的话,就等于调用number()将他转 ...
- 中科院 2014年GCT考前辅导课程安排
: 2014年GCT考前辅导课程安排 发布时间: 2014-07-14 阅读次数:1225 默认字体 9pt ...
- Cable master(二分题 注意精度)
Cable master Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26596 Accepted: 5673 Des ...
- 重构17-Extract Superclass(提取父类)
当一个类有很多方法希望将它们“提拔”到基类以供同层次的其他类使用时,会经常使用该重构.下面的类包含两个方法,我们希望提取这两个方法并允许其他类使用. public class Dog { public ...
- mysql-添加删除字段
添加字段: -- 添加字段 -- ALTER TABLE tb_name ADD 字段名称 字段类型 [完整性约束条件] [FIRST|AFTER] -- 给user10添加card字段 ); -- ...
- python pdb调试
在交互环境中通常使用pdb.run来调试: import pdb def pdb_test(arg): for i in range(arg): print(i) return arg pdb.run ...
- Centos7.5 java环境的安装配置
1.查看系统中的java环境 [root@localhost ~]# java -version openjdk version "1.8.0_101" OpenJDK Runti ...
- android目录
2013-09-121.activity生命周期 activity生命周期2 widget http://blog.csdn.net/xiang_j2ee/article/details/727564 ...
- 设置ORACLE数据库游标大小
先用超级管理员(sys)登陆服务器: sqlplus "sys/***@orcl as sysdba" 连接到:Oracle 查看ORACLE最大游标数: SQL> show ...
- ASP.NET缓存全解析1 转自网络原文作者李天平
有时候总听到网友说网站运行好慢,不知如何是好:有时候也总见到一些朋友写的网站功能看起来非常好,但访问性能却极其的差.没有“勤俭节约”的意识,势必会造成“铺张浪费”.如何应对这种情况,充分利用系统缓存则 ...