Servlet中Request的getAttribute getParameter 区别


1.从更深的层次考虑,request.getParameter()方法传递的数据,会从Web客户端传到Web服务器端,代表HTTP请求数据。 request.getParameter()方法返回String类型的数据。
   request.setAttribute()和getAttribute()方法传递的数据只会存在于Web容器内部,在具有转发关系的Web组 件之间共享。这两个方法能够设置Object类型的共享数据。
   request.getParameter()取得是通过容器的实现来取得通过类似post,get等方式传入的数据。
   

   request.setAttribute()和getAttribute()只是在web容器内部流转,仅仅是请求处理阶段。
   getAttribute是返回对象,getParameter返回字符串
 

   总的来说:request.getAttribute()方法返回request范围内存在的对象,而 request.getParameter()方法是获取http提交过来的数据。

 

2.request is something that comes from the user, attributes come from the session

 

3.Use request.getParameter() when u are planning to fetch values from a html/jsp page, and use requets.getAttribute() when u want to fetch attribute values which are set using request.setAttribute() IN A SERVLET.


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM