JSP中getParameter和getAttribute区别
(1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法
(2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter()方法来获得请求参数,
(3)当两个Web组件之间为转发关系时,转发目标组件通过getAttribute()方法来和转发源组件共享request范围内的数据。
一般通过表单和链接传递的参数使用getParameter
通过request.setAttribute("name","jerry")的方式赋值的使用request.getAttribute("name")
这个问题主要是request和session的差别,request范围较小一些,只是一个请求,简单说就是你在页面上的一个操作, request.getParameter()就是从上一个页面中的url、form中获取参数,但如果一个request涉及多个类,后面还要取参数,可以用request.setAttribute()和request.getAttribute(),但是当结果输出之后,request就结束了。
而session可以跨越很多页面,可以理解是客户端同一个IE窗口发出的多个请求。这之间都可以传递参数,比如很多网站的用户登录都用到了。
getattribute
返回的是object,需举行转换,可用setattribute设置成恣意东西,利用很机动,可随时用; 常用于servlet
页面传递参数给jsp
getparameter()是获取post/get转达的参数值;
——getattribute()是获取东西容器中的数据值;
——getparameter:用于客户端重定向时,即点击了链接或提交按扭时传值用,即用于在用表单或url重定向传值时吸取数据用。
——getattribute:用于办事器端重定向时,即在sevlet中利用了forward函数,或struts中利用了
mapping.findforward。getattribute只能收到步伐用setattribute传过来的值。
——getparameter()是获取post/get转达的参数值;
——getattribute()是获取session的值;
别的,可以用setattribute,getattribute发送吸取东西.而getparameter显然只能传字符串。
setattribute
是应用办事器把这个东西放在该页面所对应的一块内存中去,当你的页面办事怜惜定向到另一个页面时,应用办事器会把这块内存拷贝另一个页面所对应
的内存中如许getattribute就能取得你所设下的值,固然这种要领可以传东西。session也一样,只是东西在内存中的生命周期不一样罢了。
getparameter只是应用办事器在阐发你奉上来的request页面的文本时,取得你设在表单或url重定向时的值。
个人见解:
当用户把值作为链接参数传递给下个页面或serve时,其实啊也就是网页间传递数据,用
request.getparameter():提取发送过来的参数如:本网页
http://community.csdn.net/expe/topic/4633/4633804.xml?temp=.3488123
request.getparameter("temp")==".3488123"
当用户把值放在了request中的一个属性时(request.setAttribute("aa","tt"),"aa"这个属性名可以任意取的),用
getAttribute(属性名)获取.
request.getParameter()就是从上一个页面中的url、form中获取参数。但如果一个request涉及多个类,
后面还要参数,可以用request.setAttribute()和request.getAttribute(),但是当结果输出之后,request就结束了。
<form method=post>
<form
method=get>
<a
href="1.jsp?id=1">ok</a>
只能担当java.lang.string
也便是说string hotel_id
=
request.getparameter("hotel_id");
request.getattribute
是用来担当来自servlet的变量或action(着实action便是特别的 servlet)
在action中,request.setattribute("ret",ret);
只能担当java.lang.object
也便是说list ret
=
(list)request.getattribute("ret");
要是你只用jsp,底子用不到request.getattribute()
JSP中getParameter和getAttribute区别的更多相关文章
- JSP中pageEncoding和charset区别,中文乱码解决方案(转载)
转载自:JSP中pageEncoding和charset区别,中文乱码解决方案 JSP指令标签中<%@ page contentType="text/html;charset=GB23 ...
- request中getParameter和getAttribute的区别
整理一下getParameter和getAttribute的区别和各自的使用范围. (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方 ...
- 【转】HttpServletRequest.getParameter() &HttpServletRequest.getAttribute() 区别
Ref: HttpServletRequest的getParameter和getAttribute方法有什么区别 具体如下几点: (1)HttpServletRequest类有setAttribute ...
- request:getParameter和getAttribute区别
getParameter 是用来接受用post个get方法传递过来的参数的.getAttribute 必须先setAttribute.(1)request.getParameter() 取得是通过容器 ...
- JSP 中 pageEncoding 和 charset 区别以及中文乱码解决方案
一.JSP 中 pageEndcodeing 和 charset 的作用 <%@ page contentType="text/html;charset=GB2312"%&g ...
- J2EE中getParameter与getAttribute以及EL表达式${requestScope}和${param[]}
getParameter ① 得到的都是String类型的.如http://name.jsp?name=xy中的xy ② 获取POST/GET传递的参数值 ③ 用于客户端重定向,如点击链接或提交按扭时 ...
- getParameter和getAttribute区别
(1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter ...
- J2EE中getParameter与getAttribute以及对应的EL表达式
摘自http://blog.csdn.net/woshixuye/article/details/8027089 getParameter ① 得到的都是String类型的.如http://name. ...
- jsp中 response和request区别
1.response 属于重定向请求: 其地址栏的URL会改变: 会向服务器发送两次请求: 2. request 属于请求转发: 其地址栏的URL不会改变: 向服务器发送一次请求: 举一个区分它们的简 ...
随机推荐
- 在Centos 5.6下安装 redis
先引用redis官方(http://redis.io/) 的介绍: Redis is an open source, advanced key-value store.<br>It is ...
- [Redux] React Todo List Example (Adding a Todo)
Learn how to create a React todo list application using the reducers we wrote before. /** * A reduce ...
- Android之旅十八 百度地图环境搭建
在android中使用百度地图,我们能够先看看百度地图对应的SDK信息:http://developer.baidu.com/map/index.php? title=androidsdk,它里面基本 ...
- ADT下载地址整理
參考以下文章 http://developer.android.com/tools/sdk/eclipse-adt.html 整理了官网的下载地址 http://dl.google.com/andro ...
- OD: Shellcode Encoding
Shellcode 受到的限制 1. 大多数情况下 shellcode 中不允许出现 0x00 截断符,这个可以通过特殊指令来做到. 2. 有时候 shellcode 必须为可见的 ASCII 字符或 ...
- NHibernate——基本映射(5)
一.映射定义概括 1.1 映射定义(Mapping declaration) 对象和关系数据库之间的映射是用一个XML文档(XML document)来定义的.这个映射文档被设计为易读的,并且可以手工 ...
- html 页面实现指定位置的跳转
1.同页面跳转到相应位置 <a href="#id1">跳转到词条1</a> <a href="#id2">跳转到词条2&l ...
- How can I save HICON to an .ico file
refer:http://stackoverflow.com/questions/2289894/how-can-i-save-hicon-to-an-ico-file answer1: #inclu ...
- js深入理解"闭包"
一.变量的作用域 要理解闭包,首先必须理解Javascript特殊的变量作用域. 变量的作用域无非就是两种:全局变量和局部变量. Javascript语言的特殊之处,就在于函数内部可以直接读取全局变量 ...
- C++ 的多重继承
不能够从对象访问基类的公开方法,真悲剧!只能在类里面提供公共函数! void Mentor::GetInfo(){ cout<<endl<<name<<endl&l ...