HttpServletRequest的Attribute和Parameter区别
HttpServletRequest类既有getAttribute()方法,也由getParameter()方法,这两个方法有以下的组件通过getParameter()方法来获得请求参数,例如假定welcome.jsp和authenticate.jsp之间为链接关系,welcome.jsp中有以下代码:
<a href="authenticate.jsp username=weiqin">authenticate.jsp a>
html 代码
或者:
<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"); %>
html 代码
在authenticate.jsp中通过request.getParameter("username")方法来获得请求参数username:
(3)当两个Web组件之间为转发关系时,转发目标组件通过getAttribute()方法来和转发源组件共享 request范围内的用户名字,如何传递这一数据呢?先在authenticate.jsp中调用setAttribute()方法:
在hello.jsp中通过getAttribute()方法获得用户名字:Hello:
(4)从更深的数据,会从Web客户端传到Web服务器端,代表HTTP请求数据。request.getParameter()方法返回String类型的数据只会存在于Web容器内部,在具有转发关系的共享数据。
getParameter得到的。或者是http://a.jsp id=123中的数据。
getAttribute则可以是对象。
getParameter()是获取POST/GET传递的数据值;
getParameter:用于客户端重定向时,即点击了链接或提交按扭时传值用,即用于在用表单或url重定向传值时接收数据用。
getAttribute:用于服务器端重定向时,即在sevlet中使用了forward函数,或struts中使用了mapping.findForward。getAttribute只能收到程序用setAttribute传过来的一块内存中去,当你的内存中。这样getAttribute就能取得你所设下的生命周期不一样而已。
getParameter只是应用服务器在分析你送上来的文本时,取得你设在表单或url重定向时的值
HttpServletRequest的Attribute和Parameter区别的更多相关文章
- attribute与parameter区别(转)
文章转自http://blog.csdn.net/saygoodbyetoyou/article/details/9006001 request.getParameter取得Web客户端到web服务端 ...
- Request中Attribute 和 Parameter 的区别
Attribute 和 Parameter 的区别 (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为 ...
- Attribute 和 Parameter 的区别
Attribute 和 Parameter 的区别 (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为 ...
- 参数(parameter)和属性(Attribute)的区别
参数(parameter)和属性(Attribute)的区别 区别: 来源不同: 参数(parameter)是从客户端(浏览器)中由用户提供的,若是GET方法是从URL中 提供的,若是POST方法是从 ...
- [attribute|=value]和[attribute^=value]选择器区别
1.[attribute|=value] [attribute|=value]选择器说明:http://www.w3school.com.cn/cssref/selector_attribute_va ...
- jQuery的attr与prop,attribute和property区别
jQuery1.6中新添加了一个prop方法,看起来和用起来都和attr方法一样,这两个方法有什么区别呢?这要从HTMl 的attribute与property区别说起,attr与prop正是这两个东 ...
- attribute与property区别总结
在前阵子看JQuery源码中,attr()的简单理解是调用了element.getAttribute()和element.setAttribute()方法,removeAttr()简单而言是调用ele ...
- CSS选择器[attribute | = value] 和 [attribute ^ = value]的区别
前言 首先你需要知道[attribute | = value] 和 [attribute ^ = value] 分别是什么? ①:[attribute | = value] ②:[attribute ...
- parameter与attribute的使用场合(转载自草原和大树)
Attribute 和 Parameter 的区别 (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为 ...
随机推荐
- 用shell在一个文件后面的每一行追加数据
在shell分析log的时候,需要将数据过滤后转为csv的格式: 要在分析好的数据后面追加逗号: sed 's/$/&,/g' no2.log > ccc.log 结果保存在ccc.lo ...
- 定义/修改列时 NULL
mysql的文档说明: column_definition: col_name type [NOT NULL | NULL] [DEFAULT default_value] [ ...
- nginx https反向代理 tomcat
前端nginx配置 server { listen ; server_name localhost; listen ssl; ssl_certificate /usr/local/nginx/sslk ...
- C# 通过代理获取url数据
public static string doPost(string Url, byte[] postData, SinaCookie bCookie, String encodingFormat, ...
- 改变jboss部署目录(虚拟目录)
笔记: 在开发过程中,有时候我们希望将程序放在我们的源代码目录中,比如d:\code下,而不是放在jboss的deploy下,怎么办? 我们知道,jboss中集成了tomcat,因此跟tomcat一样 ...
- orm获取关联表里的属性值
ORM——关系对象模型 laravel中的Eloquent ORM用于和数据表互动,其中每个数据库表会和一个对应的「模型」互动,想要了解请查看官方文档或自行百度.获取关联表里的属性值代码如下: /** ...
- Reverse链表 递归实现
#include<iostream> struct node{ int payload; node* next; }; void bianli(node* head){ node* ite ...
- NOIP2016普及组
普及组.代码有空发. 第一题就是买铅笔.暴力模拟绝对可取. 第二题就是回文日期.从t1的年份到t2的年份枚举每一年.头尾要特判. 第三题就是海港.骗了40分. 第四题就是魔法阵.不太好优化. 完.
- Windows 环境下配置 git bash 的 HOME 默认路径
0.引 在 windows 下安装 git 之后, git 默认的HOME和~路径一般都是C:\Users\用户名,每次得用命令切换到常用的Repository下,此操作重复而没有意义.为了修改默认路 ...
- 第3天作业 PoEdu MyString实现
作业要求 代码: #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstring> class My ...