问题描述
HttpServletRequest
类中的 getAttribute()
和 getParameter()
方法有什么区别?
What is the difference between getAttribute()
and getParameter()
methods within HttpServletRequest
class?
推荐答案
getParameter()
返回 http 请求参数.那些从客户端传递到服务器的.例如http://example.com/servlet?parameter=1
.只能返回String
getParameter()
returns http request parameters. Those passed from the client to the server. For examplehttp://example.com/servlet?parameter=1
. Can only returnString
getAttribute()
仅用于服务器端使用 - 您可以使用可在同一请求中使用的属性填充请求.例如 - 您在 servlet 中设置一个属性,并从 JSP 中读取它.可用于任何对象,而不仅仅是字符串.getAttribute()
is for server-side usage only - you fill the request with attributes that you can use within the same request. For example - you set an attribute in a servlet, and read it from a JSP. Can be used for any object, not just string.这篇关于getAttribute() 和 getParameter() 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!