我也做了一些WEB 的 但是对于 getParameters()和getAttribute() 这两个属性还是不太清楚啊. 我界面表单填写的值 我用 getParameters() 可以得到 
但是什么时候用getAttribute() 呢 

解决方案 »

  1.   

    getParameters()获得的是网页传递的数据,它没有setParameters()函数。而当你要在servlet里面将传递数据的时候,就可以setAttribute("str",str),然后用getAttribute()获得了。
    用getParameters()获得的是String,getAttribute()获得的是object。
      

  2.   

    getAttribute   和   getParameter   的区别  
      1.getAttribute是取得jsp中   用setAttribute設定的attribute    
      2.parameter得到的是string;attribute得到的是object    
      3.request.getParameter()方法传递的数据,会从Web客户端传到Web服务器端,代表HTTP请求数据;request.setAttribute()和getAttribute()方法传递的数据只会存在于Web容器内部,在具有转发关系的Web组件之间共享。即request.getAttribute()方法返回request范围内存在的对象,而request.getParameter()方法是获取http提交过来的数据。  
       
      JSP中getParameter与getAttribute有何区别?  
      ——说实话,这个问题当初我也困惑很久,我也知道怎么用,可是到底有什么区别,我也不是很清楚,后来找了很多资料才明白。昨天又有一位朋友问我这个问题,想我当初同样也困惑过,于是我就把这个问题贴出来,让同样困惑的朋友解惑。  
      ——getParameter得到的都是String类型的。或者是http://a.jsp?id=123中的123,或者是某个表单提交过去的数据。  
      ——getAttribute则可以是对象。  
      ——getParameter()是获取POST/GET传递的参数值;  
      ——getAttribute()是获取对象容器中的数据值;  
      ——getParameter:用于客户端重定向时,即点击了链接或提交按扭时传值用,即用于在用表单或url重定向传值时接收数据用。  
      ——getAttribute:用于服务器端重定向时,即在sevlet中使用了forward函数,或struts中使用了 mapping.findForward。getAttribute只能收到程序用setAttribute传过来的值。  
      ——getParameter()是获取POST/GET传递的参数值;  
      ——getAttribute()是获取SESSION的值;  
      另外,可以用setAttribute,getAttribute发送接收对象.而getParameter显然只能传字符串。  
      setAttribute   是应用服务器把这个对象放在该页面所对应的一块内存中去,当你的页面服务器重定向到另一个页面时,应用服务器会把这块内存拷贝另一个页面所对应的内存中。   这样getAttribute就能取得你所设下的值,当然这种方法可以传对象。session也一样,只是对象在内存中的生命周期不一样而已。  
      getParameter只是应用服务器在分析你送上来的request页面的文本时,取得你设在表单或url重定向时的值。  
       
       
      getParameter       返回的是String,       用于读取提交的表单中的值;                
      getAttribute       返回的是Object,需进行转换,可用setAttribute设置成任意对象,使用很灵活,可随时用;  
       
         
       
      个人认为:        
          request.getAttribute():是request时设置的变量的值,用request.setAttribute("name","您自己的值");来设置值,        
          request.getParameter():提取发送过来的参数如:本网页        
          http://community.csdn.net/Expert/topic/4633/4633804.xml?temp=.3488123        
          request.getParameter("temp")==".3488123"    
       
       
      request.getParameter        
          是用来接受来自get方法或post方法的参数        
          <form       method=post>        
          <form       method=get>        
          <a       href="1.jsp?id=1">ok</a>        
          只能接受java.lang.String        
          也就是说String       hotel_id       =       request.getParameter("hotel_id");        
          request.getAttribute        
          是用来接受来自servlet的变量或Action(其实Action就是特殊的Servlet)        
          在Action中,request.setAttribute("ret",ret);        
          只能接受java.lang.Object        
          也就是说List       ret       =       (List)request.getAttribute("ret");        
          如果你只用JSP,根本用不到request.getAttribute()     
    这个比较全 帮你转过来
      

  3.   

    getParameters() getAttribute()
    两个不相干的方法,不过记住一点,要用request.getAttribute(),之前必须要有request.setAttribute(),不然是取不到东西的...
    建议你再去了解一下application,session,request的作用域问题,getAttribute()就是跟作用域有关的方法.