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. Solr查询中涉及到的Cache使用及相关的实现【转】

    转自:http://www.cnblogs.com/phinecos/archive/2012/05/24/2517018.html 本文将介绍Solr查询中涉及到的Cache使用及相关的实现.Sol ...

  2. Android 如何通过Retrofit提交Json格式数据

    本文将介绍如何通过retrofit库post一串json格式的数据.首先post的json数据格式如下: { "Id": "string", "Dev ...

  3. Android - CollapsingToolbarLayout 完全解析

    CollapsingToolbarLayout 是 google 在其推出的design libiary 中给出的一个新型控件.其可以实现的效果类似于: toolbar是透明的,有一个背景图片以及大标 ...

  4. hdu 3555 Bomb 炸弹(数位DP,入门)

    题意: 给一个数字n,求从1~n中有多少个数是含有49的,比如49,149,1490等都是含49的. 思路: 2^64也顶多是十进制的20多位,那么按十进制位来分析更简单.如果能计算k位十进制数中分别 ...

  5. COGS 2211. [BZOJ3653]谈笑风生

    ★★★★   输入文件:laugh.in   输出文件:laugh.out   简单对比时间限制:3 s   内存限制:512 MB [问题描述] 设T 为一棵有根树,我们做如下的定义: • 设a和b ...

  6. numpy.random.randint

    low.high.size三个参数.默认high是None,如果只有low,那范围就是[0,low).如果有high,范围就是[low,high). >>> np.random.ra ...

  7. c++ 中的函数调用中的参数传递

    概述 初学 \(c++\),一直搞不懂其参数传递方式.故找到一篇不错的文章:刘志华的深入探讨C++语言中参数传递问题.亲自实践一遍,并作此记录,以加深印象.     主要内容 本文主要分为五个小部分, ...

  8. Caused by: java.lang.ClassNotFoundException: java.com.bj186.ssm.controller.UserController

    在搭建SpringMVC的时候,遇到的这个问题真的很奇葩, 找不到UserController这个类 这明明不就在工程目录下吗? 经过了一番艰苦卓绝的斗争, 才发现原来是包导少了 之前导入的包是: & ...

  9. 换个语言学一下 Golang (1)

    做技术的总是有些拗.这么多年一直在.net的框框里打转转.直到现在市场上.net工作越来越难找,项目越来越老才发现不做出改变不行了.就从学习Go开始吧. Go语言的特点 简洁.快速.安全 并行.有趣. ...

  10. jquery 获得某一组name的id并合并

    var attachmentids = $("input[name='attachmentid']").map(function(){return $(this).val()}). ...