当两个Web组件之间为转发关系时,转发源会将要共享 request范围内的数据先用setAttribute将数据放入到HttpServletRequest对象中,然后转发目标通过 getParametergetParameter()方法来获得请求参数,例如假定welcome.jsp和authenticate.jsp之间为链接关系,welcome.jsp中有以下代码:

authenticate.jsp

或者:

请输入用户姓名:

在authenticate.jsp中通过request.getParameter("username"); %>

(3)getAttribute()方法来和转发源组件共享request,session范围内的数据。

假定 authenticate.jsp和hello.jsp之间为转发关系。authenticate.jsp希望向hello.jsp传递当前的用户名字, 如何传递这一数据呢?先在authenticate.jsp中调用setAttribute()方法:

<%
String username=request.%>

在hello.jsp中通过getAttribute("username"); %>
Hello: <%=username %>

从更深的层次考虑,request.getParameter()方法返回String类型的数据。

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

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

getAttribute()与getParameter的区别的更多相关文章

  1. java中getAttribute和getParameter的区别

    getAttribute表示从request范围取得设置的属性,必须要先setAttribute设置属性,才能通过getAttribute来取得,设置与取得的为Object对象类型 getParame ...

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

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

  3. getAttribute和getParameter的区别

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

  4. getAttribute与getParameter的区别

    1.getParameter得到的是字符串,其取值源于jsp页面,从jsp页面中接受一个存在的参数,多用于servlet中,用于判断业务的类型和跳转页面.如: request.getParameter ...

  5. 2017.10.16 java中getAttribute和getParameter的区别

    (1)getAttribute:表示得到 域中的对象 返回的是OBJ类型;  getParameter:表示 得到 传递的参数 返回的是String类型; 也就是getAttribute获得的值需要进 ...

  6. 基于request.getAttribute与request.getParameter的区别详解

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

  7. java中getAttribute与getParameter方法的区别

    知识点1:getAttribute表示从request范围取得设置的属性,必须要先setAttribute设置属性,才能通过getAttribute来取得,设置与取得的为object对象类型 例: r ...

  8. getAttribute和getParameter的简单区别

    getAttribute表示从request范围取得设置的属性,必须要先setAttribute设置属性,才能通过getAttribute来取得,设置与取得的为Object对象类型 getParame ...

  9. getAttribute和getParameter

    getAttribute表示从request范围取得设置的属性,必须要先setAttribute设置属性,才能通过getAttribute来取得,设置与取得的为Object对象类型 getParame ...

随机推荐

  1. js-事件委托

    事件委托一般用于动态生成的元素中使用,如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8& ...

  2. VS2010字体优化

    文本编辑器:Consolas 环境字体:微软雅黑

  3. RxJava漫谈-RxAndroid使用

    RxJava在github上的地址:https://github.com/ReactiveX/RxJava RxAndroid在github上的地址:https://github.com/Reacti ...

  4. Catel(翻译)-为什么选择Catel

      1. 介绍        这篇文章主要是为了说明,我们为什么要使用Catel框架作为开发WPF,Silverlight,和Windows phone7应用程序的开发框架.   2. 通用功能 2. ...

  5. css3滚动提示

    <css揭秘>书中,滚动提示的实现 <!DOCTYPE html> <html lang="en"> <head> <meta ...

  6. 你不了解PHP的10件事情

    看到有人翻译的<10 things you (probably) didn’t know about PHP>,发现在此次之前2.8两条并不知道,1.3虽然熟知但是去没有实际应用. 由于阅 ...

  7. Python番外 事务 那些事

    Transaction 也就是所谓的事务了,通俗理解就是一件事情.从小,父母就教育我们,做事情要有始有终,不能半途而废. 事务也是这样,不能做一般就不做了,要么做完,要么就不做.也就是说,事务必须是一 ...

  8. SDWebImage 官方文档

    API documentation is available at CocoaDocs - SDWebImage Using UIImageView+WebCache category with UI ...

  9. Detecting an Ajax request in PHP

    1:index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  10. 面试题 46 1+ 2+3+...+n

    class Temp{ public: Temp(){ ++N; sum+=N; } static void Reset(){ N = ; sum = ; } static int getSum(){ ...