getParameter()和getAttribute()的区别在哪??

解决方案 »

  1.   

    我觉得简单的来说,parameter 是在url中类似?name=abc&password=xyz这样的值,
    而attribute是存储在request或session中的,要调用getAttribute(“name”),必须先调用setAttribute(“name“, ”abc“);
      

  2.   

    getParameter(name)是获取JSP地址栏中的参数name或者form表单中id(或者name)=name的控件的值
    getAttribute(name)是获取pageContext/request/Session/Application中key=name的事先存储在Attribute中的值
      

  3.   

    同意1楼
    getParameter()是从请求中获得参数值
    而getAttribute()是获得属性值
    session等jsp内置对象类似于Map,使用key-value方式保存数据
    在webwork中已经将session封装为Map对象
      

  4.   


    getParameter(name)是获取JSP地址栏中的参数name或者form表单中id(或者name)=name的控件的值
    getAttribute(name)是获取pageContext/request/Session/Application中key=name的事先存储在Attribute中的值 
     如果需要取对象的时候是getAttribute(name)
      

  5.   

    get attribute 用来返回指定的属性值,如果不存在这个属性,返回null值
    get parameter 获得指定名称的客户端提交的参数的值
      

  6.   

    form提交(method=get/post)或超连接(xxx.jsp?xx='xxx')时,接收值时用getParameter();
    当用session或request等的request.setAttribute()时;取值时用get attribute';