getAttribute() 和 getParameter() 的区别 [英] Difference between getAttribute() and getParameter()

查看:25
本文介绍了getAttribute() 和 getParameter() 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 example http://example.com/servlet?parameter=1. Can only return String

      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() 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆