JSP中getParameter getAttribute 区别 详解

来源:互联网 发布:增删算法统宗 编辑:程序博客网 时间:2024/05/28 09:32


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

例子:  

request. setAttribute("key","value");

request. getAttribute("key");

得到的结果就是value

getAttribute   和   getParameter   的区别 
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提交过来的数据。  

内存原理:setAttribute   是应用服务器把这个对象放在该页面所对应的一块内存中去,当你的页面服务器重定向到另一个页面时,应用服务器会把这块内存拷贝另一个页面所对应的内存中。   这样getAttribute就能取得你所设下的值,当然这种方法可以传对象。session也一样,只是对象在内存中的生命周期不一样而已。 
getParameter只是应用服务器在分析你送上来的request页面的文本时,取得你设在表单或url重定向时的值。 

原创粉丝点击