request.getAttribute("username");
 request.getParameter("username");
有什么区别?应有在那种场景

解决方案 »

  1.   

    attribute是属性,是在request域生命周期内放入,并在request生命周期内使用,是web服务器内部的变量
    parameter是参数,是在不依赖request生命周期,是通过http协议进行传输的,是浏览器和服务器交互的数据。
      

  2.   

    Parameter是指页面传递过来的参数;
    对于Attribute,你可以简单的这样理解,requset对象中有一个Map类型的属性,根据一个Key值取得对应的value,这就是attribute。
      

  3.   

    request.getAttribute("username");不依赖于HTTP协议
    request.getParameter("username");依赖于HTTP协议
      

  4.   

    Attribute  跟 HTTP 协议无关
    Parameter  跟 HTTP 协议有关
    Attribute 可以放入 自己命名的变量
    Parameter 只能是表单 或者 参数传递
     
      

  5.   

    通俗点说,
    request.getAttribute("username")想取到值,相关form就要有这个属性,
    request.getParameter("username")的话只要在url中有,就能取到
      

  6.   

    一个返回Object
    一个返回String