getParameter和getAttribute的区别是什么?

xxmm 2001-07-22 09:18:05
...全文
1174 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
armyshu 2002-02-19
  • 打赏
  • 举报
回复
getParameter只能传递string类型的变量,getAttribute能传递vector!
gzwrj 2002-02-11
  • 打赏
  • 举报
回复
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
Attributes can be set two ways. The servlet container may set attributes to make available custom information about a request. For example, for requests made using HTTPS, the attribute javax.servlet.request.X509Certificate can be used to retrieve information on the certificate of the client. Attributes can also be set programatically using setAttribute(java.lang.String, java.lang.Object). This allows information to be embedded into a request before a RequestDispatcher call.

Attribute names should follow the same conventions as package names. This specification reserves names matching java.*, javax.*, and sun.*.

Parameters:
name - a String specifying the name of the attribute
Returns:
an Object containing the value of the attribute, or null if the attribute does not exist

//
getParameter
public java.lang.String getParameter(java.lang.String name)
Returns the value of a request parameter as a String, or null if the parameter does not exist. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.
You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use getParameterValues(java.lang.String).

If you use this method with a multivalued parameter, the value returned is equal to the first value in the array returned by getParameterValues.

If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the body directly via getInputStream() or getReader() can interfere with the execution of this method.

Parameters:
name - a String specifying the name of the parameter
Returns:
a String representing the single value of the parameter
See Also:
getParameterValues(java.lang.String)
muwenyi 2002-02-10
  • 打赏
  • 举报
回复
getParameter可以获得客户端传送给服务器端的参数值。

getAttribute可以得到由setAttribute设置的参数值,就相当于是使用getAttribute得到一个自己定义的参数,而不是从客户端得到的参数。我是这样理解的!
xxmm 2001-07-22
  • 打赏
  • 举报
回复
系统属性指什么?能不能给一个例子?
yelz 2001-07-22
  • 打赏
  • 举报
回复
getParameter 返回上个页面提交得参数,getAttribute返回系统属性,不同jsp服务器可能不同。

81,094

社区成员

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

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