zoukankan      html  css  js  c++  java
  • request.getParameter与request.getAttribute()

    这里就request为例,不去考虑session。

    request对象是javax.servlet.http.HttpServletRequest接口的一个实例,request表示调用JSP页面的请求,如request.getParameter(“paramName”)表示获得Form提交过来的参数。

    request.getParameter()返回的是Web客户端向Web服务器端传送数据。

    HttpServletRequest类没有setParameter()方法,request.getParameter()用于获取http表单中提交过来的数据,返回的是String类型。

    request.setAttribute()和getAttribute()是发生在Web容器内部之间的数据传递,在具有转发关系的Web组件之间共享。

    request.getAttribute()方法返回request范围内存在的对象,返回的是Object。setAttribute 是Web服务器把这个对象放在该页面所对应的一块内存中去,当你的页面服务器内部重定向到另一个页面时,应用服务器会把这块内存拷贝另一个页面所对应的内存中。

    补充:

    public interface HttpServletRequest extends ServletRequest

    getParameter()是在服务器端获得客户端传送的数据(表单提交,或地址栏参数等)。

    setAttribute()指的是在服务器端已经获得了request之后,又往request中增加新的属性,只有set之后,才能有get操作。getAttribute()是一个Object类型的,需要进行向下类型转换。

    一般servlet用setAttribute,getAttribute;jsp用getParameter。

  • 相关阅读:
    三元表达式
    迭代器
    python字符串内的自建函数 string.
    shell下的while和if
    正则表达
    nginx下同时做负载均衡和web服务
    nfs匹配nginx服务
    yum安装nginx的负载均衡详解
    samba实战讲解
    python基础之数据类型
  • 原文地址:https://www.cnblogs.com/suizhikuo/p/3581299.html
Copyright © 2011-2022 走看看