request.getAttribute()和request.getParameter()的区别是request.getAttribute()获得的是对象类型,而request.getParameter()获得的是字符串类型
一般的网页应用,基本上是基于Post方式的传递,用getParameter取值。对于自己控制的,可以通过request.setAttribute和getAttribute 实现值得传递。
对于应用Structs框架的,getAttribute用的多一点,其他的基本上用getParameter
我的理解:
session.getAttribute();获得session
request.getParameter();获得parameter
1.getParameter可以获得客户端传送给服务器端的参数值。
getAttribute可以得到由setAttribute设置的参数值,就相当于是使用getAttribute得到一个自己定义的参数,而不是从客户端得到的参数。
2.getParameter只能传递string类型的变量,getAttribute能传递vector。
getParameter(),获取表单的值 getAttribute()获得session的值
getParameterNames() 获得表单或则url中的参数的数组
getattributeNames():返回request对象所有属性的名字,结果集是一个Enumeration(枚举)类的实例
根据楼上,是不是 getParameter()得到的值如果下次不提交或保存起来的话,下次重定向后就没啦?
:理解对了
getAttribute()所要得到的属性值因为存在session中,所以重定向后仍可以取出?
getAttribute()在request和session中都有,只是作用域不同,在取之前肯定是要在某个地方存一下,这种东东可以存取对象
http://community.csdn.net/Expert/topic/4763/4763471.xml?temp=.1793177
看见后面的?temp=.1793177没有,?号后面的这个东西用request.getAttribute("temp")就能得到字符串".1793177",
而getAttribute()之前,你必须在页面或者逻辑中用serAttribute()设置了才能用,已经很清楚了,我不再说了哈
Parameter是html裡傳來的像 checkbox textfield password radio ...的value
getAttribute是取得jsp中用setAttribute設定的attribute
還有....
parameter得到的是string
attribute得到的是object
HttpServletRequest类既有getAttribute()方法,也由getParameter()方法,这两个方法有以下区别:
(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传递当前的用户名字,如何传递这一数据呢?先在authenticate.jsp中调用setAttribute()方法:
<%
String username=request.getParameter("username");
request.setAttribute("username",username);
%>
<jsp:forward page="hello.jsp" />
在hello.jsp中通过getAttribute()方法获得用户名字:
<% String username=(String)request.getAttribute("username"); %>
Hello: <%=username %>
request.getParameterValues与request.getParameter的区别:
request.getParameterValues(String name)是获得如checkbox类(名字相同,但值有多个)的数据。 接收数组变量,如checkobx类型
request.getParameter(String name)是获得相应名的数据,如果有重复的名,则返回第一个的值. 接收一般变量,如text类型