URL:http://localhost:8888/Test/index.jsp?test=123
 <body>
${test}
    ${requestScope.test}  
    <%request.getAttribute("test"); %>
</body>
以上代码均不能取出值
仅当 使用
<%
request.setAttribute("test", "123");
%>
赋值时<body/>内可以正常取出值

那么如何取出URL 中的test 的值呢?如下
  <body>
${param.test}
    <%=request.getParameter("test") %>
</body>
均可取出URL中的test的值。。
结论:

${param.name} 等价于 request.getParamter("name"),这两种方法一般用于服务器从页面或者客户端获取的内容。

${requestScope.name} 等价于 request.getAttribute("name"),一般是从服务器传递结果到页面,在页面中取出服务器保存的值。

HttpServletRequest类既有getAttribute()方法,也由getParameter()方法,这两个方法有以下区别:

(1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法

(2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter()方法来获得请求参数,例如假定welcome.jsp和authenticate.jsp之间为链接关系,welcome.jsp中有以下代码:

<a href="authenticate.jsp?username=weiqin">authenticate.jsp </a>  //  这种参数形式是超链接带参数
或者:
<form name="form1" method="post" action="authenticate.jsp">   //这种方式是表单提交的形式
   请输入用户姓名:<input type="text" name="username">
   <input type="submit" name="Submit" value="提交">
</form>

在authenticate.jsp中通过request.getParameter("username")方法来获得请求参数username:
<% String username=request.getParameter("username"); %>

(3)当两个Web组件之间为转发关系时,转发目标组件通过getAttribute()方法来和转发源组件共享request范围内的数据。

假定authenticate.jsp和hello.jsp之间为转发关系。authenticate.jsp希望向hello.jsp传递当前的用户名字,如何传递这一数据呢?

先在authenticate.jsp中调用setAttribute()方法:

<%
String username=request.getParameter("username");
request.setAttribute("username",username);
%>
<jsp:forward page="hello.jsp" />
在hello.jsp中通过getAttribute()方法获得用户名字:
% String username=(String)request.getAttribute("username"); %>
Hello: <%=username %>

从更深的层次考虑,

request.getParameter()方法传递的数据,会从Web客户端传到Web服务器端,代表HTTP请求数据。

request.getParameter()方法返回String类型的数据。

request.setAttribute()和getAttribute()方法传递的数据只会存在于Web容器内部,在具有转发关系的Web组件之间共享。

这两个方法能够设置Object类型的共享数据

简单来讲request.getParamenter()方法使用的是HTTP协议来传递数据,只能传递String类型的信息,而request.setAttribtute()方法传递数据是在WEB容器中传递,可以转发任意类型的对象信息,比如一个listAction的servlet想传给list.jsp一个LIST集合,则必须使用setAttribute方法。

getParameter getAttribute的更多相关文章

  1. request:getParameter getAttribute

    转载自:http://www.cnblogs.com/shaohz2014/p/3804656.html 在浏览器地址输入,表示传入一个参数test,值为123 http://localhost:88 ...

  2. request getParameter getAttribute

    在浏览器地址输入,表示传入一个参数test,值为123 http://localhost:8888/Test/index.jsp?test=123 在index.jsp中尝试使用EL表达式取出,代码如 ...

  3. request中getParameter和getAttribute的区别

    整理一下getParameter和getAttribute的区别和各自的使用范围. (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方 ...

  4. getattribute()与getparameter()的区别

    1.它们取到的值不同.getAttribute取到的是对象(object),而getParameter取到的是String. 2.数据传递路劲不同.request.getParameter方法传递的数 ...

  5. JSP中request getParameter和getAttribute不同(转载)

    (1)request.getParameter()取得是通过容器的实现来取得通过类似post,get等方式传入的数据,,request.setAttribute()和getAttribute()只是在 ...

  6. getAttribute和getParameter的区别

    2016年1月19日JSP中getParameter与getAttribute有何区别? ——getParameter得到的都是String类型的.或者是http://a.jsp?id=123中的12 ...

  7. J2EE中getParameter与getAttribute以及EL表达式${requestScope}和${param[]}

    getParameter ① 得到的都是String类型的.如http://name.jsp?name=xy中的xy ② 获取POST/GET传递的参数值 ③ 用于客户端重定向,如点击链接或提交按扭时 ...

  8. request.getAttribute() 和 request.getParameter() 有何区别?

    HttpServletRequest类既有getAttribute()方法,也由getParameter()方法,这两个方法有以下区别: (1)HttpServletRequest类有setAttri ...

  9. request.getParameter与request.getAttribute()

    这里就request为例,不去考虑session. request对象是javax.servlet.http.HttpServletRequest接口的一个实例,request表示调用JSP页面的请求 ...

随机推荐

  1. Hive_Hive的安装

    嵌入模式不推荐使用. 本地模式多用于开发和测试. 远程模式多用于生产环境.

  2. centos下svn的ldap认证配置

    前提:完成svn的基本安装 一.安装sasl相关组件 #yum install -y cyrus-sasl cyrus-sasl-lib cyrus-sasl-plain 二.查看SASL版本和提供的 ...

  3. Jmeter(二十三)稳定性测试后的波形图

    jmeter-plugins.org 这个网站为 JMeter 提供了一些增强型功能的插件,使用起来就像 Eclipse 装插件一样,完全做到了插件的可插拔特性.本文简要介绍如何使用这些插件让你的 J ...

  4. keil_rtx特点

    Keil RTX是一个专为ARM及Cortex M系列处理器开发的无版税的确定的实时操作系统.它允许工程师建立多任务同步并行的程序软件,同时也能帮助使程序代码更加结构化和便于维护.   产品亮点 所有 ...

  5. elasticsearch的模糊查询

    https://blog.csdn.net/a772304419/article/details/78951561

  6. .Net魔兽登录页面

    一,页面部分展示 二.代码展示 1.登录页面: public partial class FrmLogin : Form { public FrmLogin() { InitializeCompone ...

  7. 一些JS基本小内容

    获取select选中内容: 1.获取select表单内容 <select id="sel"> <option value="v1">1& ...

  8. Redis的下载安装

    Redis官网只提供了Linux版,MicroSoft自己搞了个Windows版,可在GitHub下载: https://github.com/microsoftarchive/redis/relea ...

  9. jQuery3.2.1 和2.0和 1区别

    1. 移除旧的IE工作区新的最终版最主要的目标是更加快速,更加时尚,因此,那些支持早于IE9版本的相关技术与工作区都被移除了.这意味着如果你想要或者需要支持IE6-8,你必须用回1.12版本,因为甚至 ...

  10. OpenCV中CvMat的初始化[转]

    一)cvCreateMat创建和分配数据CvCreateMat会创建CvMat,并为CvMat分配数据.cvCreateMat可以配合cvInitMatHeader来初始化CvMat对象.因为CvCr ...