当两个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. 重学《C#高级编程》(继承)

    前两天重新看了<C#高级编程>里的第四章:继承与第六章:数组.OOP三大特性:封装,继承,多态,个人感觉继承是实现多态的基础,包括以后接触的设计模式,都是继承特性的衍生. 继承特性有两种, ...

  2. canvas.toDataURL(type, args)

    canvas.toDataURL(type, args)该方法能够将canvas转换为图像,图像是基于Base64编码的.如果不指定两个参数,无参数调用该方法,转换的图像格式为png格式 •type: ...

  3. DataGrid 简单数据绑定实例1

    1.默认数据显示(自动显示列) 后台绑定 //DataGrid 数据绑定 dataGridOne.ItemsSource = _Context.Info.ToList(); 前台定义 <Data ...

  4. C#实现测量程序运行时间及cpu使用时间

    private void ShowRunTime() { TimeSpan ts1 = Process.GetCurrentProcess().TotalProcessorTime; Stopwatc ...

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

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

  6. 解决Linux下Oracle中文乱码的一些心得体会 ,转自

    以下转自 http://blog.itpub.net/29151695/viewspace-1173238/ 最近在linux上安装完oracle 10gR2后,又遇到了字符集乱码的问题,之前在网上找 ...

  7. 打开较大存储量的.sql文件时,出现SQL Server 阻止了对组件 'xp_cmdshell' 的 过程'sys.xp_cmdshell' 的访问

    1. “消息 15281,级别 16,状态 1,过程 xp_cmdshell,第 1 行SQL Server 阻止了对组件 'xp_cmdshell' 的 过程'sys.xp_cmdshell' 的访 ...

  8. PHP正则表达式屏蔽电话号码中间段

    要屏蔽电话号码中间段,首先要知道电话号码的正则表达式. 先来看看PHP匹配电话号码的正则表达式. 匹配固定电话的正则表达式为: /(0[0-9]{2,3}[\-]?[2-9][0-9]{6,7}[\- ...

  9. MySQL性能分析脚本

    #!/usr/bin/python #!coding:utf-8 import mysql.connector as connector import json """ ...

  10. MySQL锁等待分析【2】

    MySQL锁等待分析[1]中对锁等待的分析是一步一步来的.虽然最后是分析出来了,可是用时是比较长的:理清各个表之间的关系后,得到如下SQL语句,方便以后使用 select block_trx.trx_ ...