求教getAttribute()和getParameter()的区别

cathl 2006-05-19 11:13:20
一直没弄明白getAttribute()和getParameter(),getAttributeNames()和getParameterNames()的区别,求教!
...全文
398 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dreamover 2006-05-19
  • 打赏
  • 举报
回复
getParameter()和getAttribute()根本就是两种东西,这也能混?
harston 2006-05-19
  • 打赏
  • 举报
回复
根据楼上,是不是 getParameter()得到的值如果下次不提交或保存起来的话,下次重定向后就没啦?
:理解对了
getAttribute()所要得到的属性值因为存在session中,所以重定向后仍可以取出?
getAttribute()在request和session中都有,只是作用域不同,在取之前肯定是要在某个地方存一下,这种东东可以存取对象
cathl 2006-05-19
  • 打赏
  • 举报
回复
根据楼上,是不是 getParameter()得到的值如果下次不提交或保存起来的话,下次重定向后就没啦?getAttribute()所要得到的属性值因为存在session中,所以重定向后仍可以取出?
cathl 2006-05-19
  • 打赏
  • 举报
回复
理解了通过request.getParamter(String name)可以检索HTML表单所提交的数据或URL上的查询
字符串;
getAttribute(String name)是根据给定的属性名返回所绑定的属性,但不知这些属性是什么,存在哪里,在什么情况下要用到setAttribute&getAttribute来存取属性
zuguanqun 2006-05-19
  • 打赏
  • 举报
回复
getParameter(),获取表单的值 getAttribute()获得session的值

getParameterNames() 获得表单或则url中的参数的数组
getattributeNames():返回request对象所有属性的名字,结果集是一个Enumeration(枚举)类的实例
glok 2006-05-19
  • 打赏
  • 举报
回复
1.getParameter可以获得客户端传送给服务器端的参数值。

getAttribute可以得到由setAttribute设置的参数值,就相当于是使用getAttribute得到一个自己定义的参数,而不是从客户端得到的参数。

2.getParameter只能传递string类型的变量,getAttribute能传递vector。
挑大梁 2006-05-19
  • 打赏
  • 举报
回复
我的理解:
session.getAttribute();获得session

request.getParameter();获得parameter



harston 2006-05-19
  • 打赏
  • 举报
回复
呵呵
http://community.csdn.net/Expert/topic/4763/4763471.xml?temp=.1793177
看见后面的?temp=.1793177没有,?号后面的这个东西用request.getAttribute("temp")就能得到字符串".1793177",
而getAttribute()之前,你必须在页面或者逻辑中用serAttribute()设置了才能用,已经很清楚了,我不再说了哈
good__student 2006-05-19
  • 打赏
  • 举报
回复
楼上说的是:
getParameter()是得到其他页面对本页的请求
getAttribute()是得到自己定义的session的参数
cathl 2006-05-19
  • 打赏
  • 举报
回复
to: drearmover
讲讲?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧