Servlet-获取页面的元素的值的方式以及区别

  1. request.getParameter() 返回客户端的请求参数的值;request.getParameterNames() 返回所有可用属性名的枚举; request.getParameterValues() 返回包含参数的所有值的数组。

  2. request.getAttribute()。

  用途上:

  • request.getAttribute(), 一般用于获取request域对象的数据(在跳转之前把数据使用setAttribute来放到request对象上)

  • request.getParameter(), 一般用于获取客户端提交的参数

  

  存储数据上:

  • request.getAttribute()可以获取Objcet对象

  • request.getParameter()只能获取字符串(这也是为什么它一般用于获取客户端提交的参数)

猜你喜欢

转载自www.cnblogs.com/hongchengshise/p/10371741.html