摘在网上:
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.
本文深入探讨了Web开发中HTTP请求数据与Web容器内部数据的区别及使用场景,详细介绍了request.getParameter()和request.setAttribute()/getAttribute()方法的功能与用途。

883

被折叠的 条评论
为什么被折叠?



