1.getAttribute是取得jsp中 用setAttribute設定的attribute

2.parameter得到的是string;attribute得到的是object

3.request.getParameter()方法传递的数据,会从Web客户端传到Web服务器端,代表HTTP请求数据;request.setAttribute()和getAttribute()方法传递的数据只会存在于Web容器内部,在具有转发关系的Web组件之间共享。即request.getAttribute()方法返回request范围内存在的对象,而request.getParameter()方法是获取http提交过来的数据。

JSP中getParameter与getAttribute有何区别?

——getParameter得到的都是String类型的。或者是http://a.jsp?id=123中的123,或者是某个表单提交过去的数据。

——getAttribute则可以是对象,返回的类型是Object。

——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重定向时的值。

getParameter 返回的是String, 用于读取提交的表单中的值;

getAttribute 返回的是Object,需进行转换,可用setAttribute设置成任意对象,使用很灵活,可随时用;

getParameter和getAttribute有什么区别的更多相关文章

  1. Request的getParameter和getAttribute方法的区别

    下面整理一下getParameter和getAttribute的区别和各自的使用范围.      (1)HttpServletRequest类有setAttribute()方法,而没有setParam ...

  2. request中getParameter和getAttribute的区别

    整理一下getParameter和getAttribute的区别和各自的使用范围. (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方 ...

  3. 【转】HttpServletRequest.getParameter() &HttpServletRequest.getAttribute() 区别

    Ref: HttpServletRequest的getParameter和getAttribute方法有什么区别 具体如下几点: (1)HttpServletRequest类有setAttribute ...

  4. request.getParameter()与request.setAttribute()的区别 (转载)

    request.getParameter()与request.setAttribute()的区别 request.getParameter(),request.setAttribute()区别如下: ...

  5. Request的getParameter和getAttribute方法的差别

    HttpServletRequest.getParameter("modelName");能取到想要的modelObject吗?经过測试之后.发现是不能的. 后来想想.其它道理挺简 ...

  6. getAttribute 与getParmeter 区别

    1.getAttribute是取得jsp中 用setAttribute設定的attribute 2.parameter得到的是string:attribute得到的是object 3.request. ...

  7. JSP中getParameter和getAttribute区别

    (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter ...

  8. getParameter和getAttribute区别

    (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter ...

  9. getParameter和getAttribute的区别

    1.getAttribute 是取得jsp中 用setAttribute 设定的attribute 2.parameter得到的是String:attribute得到的是object 3.reques ...

随机推荐

  1. iOS笔记之AutoresizingMask

    在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高. enum {   UIViewAutoresi ...

  2. Javascript几种创建对象的方法

    1.工厂方法 demo.js 1 2 3 4 5 6 7 8 9 10 11 function createPerson(name, age) { var person = new Object(); ...

  3. 穷举算法和递推算法(Java)

    穷举算法 概念: 最简单算法,依赖计算机的强大计算能力穷尽每一种可能的情况.穷举算法效率不高,但是适合一些没有明显规律可循的场合. 思想: 在使用穷举算法时,需要明确问题答案的范围,这样才可能在指定范 ...

  4. DDMS介绍

    DDMS全称:Dalvik Debug Monitor Service 一,DDMS的作用 它提供了截屏.查看线程和堆信息.logcat.进程.广播状态信息.模拟来电呼叫和短信.虚拟地理坐标等等. 二 ...

  5. tornado框架的get方法传递参数

    tornado框架的get方法传递参数,代码: # encoding: utf-8 """ @version: ?? @author: andu99 @contact: ...

  6. QT Creator快捷键不能用

    我现在搞明白了,热键之所以不行,是因为我开了Fakevim原因.关了fakevim就能用热键了. 如果开了Fakevim,连基本的Ctrl+C,这样的复制快捷键都不能用. 快速添加方法实体(.cpp) ...

  7. 汉诺塔的c++实现

    void hanNuoTa(int n,int a,int b,int c) { ) return; hanNuoTa(n - , a, c, b); cout << n << ...

  8. iOS-----简易地CocoaAsyncSocket使用

    CocoaAsyncSocket使用 代理的.h文件 //GCDAsyncSocketDelegate执行代理对象 #import <Foundation/Foundation.h> #i ...

  9. 无线路由器的加密模式WEP,WPA-PSK(TKIP),WPA2-PSK(AES) WPA-PSK(TKIP)+WPA2-PSK(AES)。

    目前无线路由器里带有的加密模式主要有:WEP,WPA-PSK(TKIP),WPA2-PSK(AES)和WPA-PSK(TKIP)+WPA2-PSK(AES). WEP(有线等效加密)WEP是Wired ...

  10. gqlgen golang graphql server 基本试用

    gqlgen golang 的graphql server 具体代码参考https://github.com/rongfengliang/gqlgen-demo 特点 模型优先 类型安全 代码生成 安 ...