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. HTML表格的基本结构标记

    <table>标记 1.基本格式:<table 属性1="属性值1" 属性2="属性值2" ... ...>表格内容</table ...

  2. python学习之j进程和线程:

    每个进程至少有一个线程,python因为每个线程都共用一个GIL全局锁(同时只能运行一个线程),所以不能用多线程(除非重新写C解释器),但是多进程的GIL锁各自独立可多进程. 进程与线程的区别在于一个 ...

  3. python_21(Django中间件)

    第1章 中间件 1.1 介绍 1.2 种类 1.3 自定义中间件 1.4 process_request 1.4.1 注册中间件 1.5 process_response 1.6 process_vi ...

  4. CSS浮动float父div没有高度的问题

    如下所示,子元素 div2 本身具有高度和宽度,但由于其具有float:left:属性后.其父元素 div1 不具有高度. <html>    <head>    </h ...

  5. Django的学习需要掌握的一些基础和初步搭建自己的框架

    一.Django的学习需要掌握的一些基础 第一个需要注意的点:客户端发送过来的数据结构组成: 第二个需要注意的点:动态网页和静态网页 静态网页:用户发送请求,服务端找到对应的静态文件返回给浏览器,静态 ...

  6. P1216 [USACO1.5]数字三角形 Number Triangles

    题目描述 观察下面的数字金字塔. 写一个程序来查找从最高点到底部任意处结束的路径,使路径经过数字的和最大.每一步可以走到左下方的点也可以到达右下方的点. 7 3 8 8 1 0 2 7 4 4 4 5 ...

  7. 声明已被否决 VS C++

    error C4996声明已被否决,不止一次碰到这个问题,在这里必须mark一下! 尝试这个1.Project Properties > Configuration Properties > ...

  8. 屏幕旋转时 Activity 的生命周期 —— 测试与结论

    关于 Android 手机横竖屏切换时 Activity 的生命周期问题,网上有很多相似的文章,大多数都是说明在竖屏切换横屏时 Activity 会重启一次,而在横屏切换竖屏时 Activity 会重 ...

  9. history 路由且带二级目录的Apache配置

    有多个项目目录的时候 由于项目不知一个,所以不得不为每一个项目建一个专有的文件夹,这就导致了在配置nginx的时候会出现二级目录   - step1: 修改 vue.config.js   添加配置 ...

  10. 120. Triangle 以及一个多维vector如何初始化

    1.刚开始result的初始化写的是vector<vector<int>> result,然后再去对result[0][0] = triangle[0][0]赋值,一直报错.老 ...