- 浏览: 480500 次
- 性别:
- 来自: 沈阳
文章分类
- 全部博客 (437)
- Windows设置 (2)
- oracle数据库 (39)
- bug--jsp (4)
- j2se (13)
- js (40)
- bug-tomcat不能启动程序 (1)
- Hibernate (29)
- eclipse (20)
- java (65)
- 设计模式 (6)
- bug (18)
- PL/SQL (11)
- 前台 (5)
- 杂谈 (25)
- UML (1)
- jdbc编程 (2)
- 技术调研 (1)
- 数据通信 (2)
- ios (1)
- servlet自学笔记 (10)
- tomcat (9)
- SQL学习笔记 (6)
- java工具 (1)
- 数据库设计 (4)
- javascript (10)
- jsp (11)
- struts (17)
- ajax (7)
- linix/Unix (6)
- 资源 (3)
- spring (14)
- 算法 (5)
- 计算机网络 (2)
- http (5)
- c++ (2)
- web应用 (3)
- jvm (5)
- java中的字符编码 (14)
- java代码库 (2)
- classloader (1)
- 读书笔记 (1)
- c (1)
- 开源软件 (1)
- svn (1)
- AOP (1)
- java序列化 (1)
- 多线程 (4)
- The legendary programmers (1)
- Apache http Server (1)
- html tag (3)
- struts1.X学习笔记 (5)
- buffalo (1)
- 自己收藏 (0)
- TOEFL(IBT) (1)
- 网络翻墙 (0)
- 编译原理 (1)
- 书籍推荐 (1)
- css (10)
- javaee环境搭建资料 (1)
- 开源工具 (1)
- 美国生活 (1)
- spring自学 (3)
- log4j (3)
- 算法与数据结构 (5)
- 病毒,插件处理大全 (1)
- flex (2)
- webservice (1)
- git (7)
- cs (1)
- html (4)
- javaee (6)
- 开车 (0)
- springmvc (3)
- 互联网架构 (2)
- intellij idea (18)
- maven (15)
- mongodb (2)
- nginx (1)
- react (3)
- java基础例子 (2)
- springboot (2)
- 培训 (5)
- mysql (3)
- 数据库 (3)
- 生活 (2)
- intellij (3)
- linux (2)
- os (3)
最新评论
-
潇洒天涯:
[color=blue][color=cyan] ...
oracle 通过 nvl( )函数sql 查询时为 空值 赋默认值 -
hekai1990:
受教了..
oracle中的varchar2
HttpServletRequest.getParameter("modelName"); 能取到想要的modelObject吗?经过测试之后,发现是不能的。后来想想,其他道理挺简单的,当两个Web组件之间为转发关系时,转发源会将要共享 request范围内的数据先用setAttribute将数据放入到HttpServletRequest对象中,然后转发目标通过 getAttribute方法来取得要共享的数据。而MVC中用的就是Web组件之间的转发啊!真是笨,怎么当时没有想到呢?
下面整理一下getParameter和getAttribute的区别和各自的使用范围。 (1)HttpServletRequest类有setAttribute()方法,而没有setParameter()方法 (2)当两个Web组件之间为链接关系时,被链接的组件通过getParameter()方法来获得请求参数,例如假定welcome.jsp和authenticate.jsp之间为链接关系,welcome.jsp中有以下代码: (3)当两个Web组件之间为转发关系时,转发目标组件通过getAttribute()方法来和转发源组件共享request范围内的数据。 假定 authenticate.jsp和hello.jsp之间为转发关系。authenticate.jsp希望向hello.jsp传递当前的用户名字, 如何传递这一数据呢?先在authenticate.jsp中调用setAttribute()方法: request.setAttribute()和getAttribute()只是在web容器内部流转,仅仅是请求处理阶段。 getAttribute是返回对象,getParameter返回字符串
<a href="authenticate.jsp?username=wolf">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"); %>
<%
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.getParameter()取得是通过容器的实现来取得通过类似post,get等方式传入的数据。
总的来说:request.getAttribute()方法返回request范围内存在的对象,而request.getParameter()方法是获取http提交过来的数据。
发表评论
-
【转】JAVA泛型通配符(PECS)
2018-07-29 10:43 477在JAVA的泛型集合中,默认都可以添加null,除此以外, ... -
Differences between notify() and notifyAll()
2018-07-16 09:01 475Notification to number of th ... -
【转】深度解析Java多线程的内存模型
2018-07-16 09:00 447https://www.jianshu.com/p/a3f ... -
【转】java rmi
2018-01-03 18:57 357此处讲的是Java中的RMI ... -
Java Annotation认知(包括框架图、详细介绍、示例说明)
2017-10-09 19:49 343摘要 Java Annotation是JDK5.0引入的 ... -
【转】web.xml 配置404和500错误的自定义页面
2016-01-03 15:16 1274web.xml Xml代码 &l ... -
关于java的binding
2013-06-16 22:51 626//file: MyMain.class class B ... -
【转】web.xml 中的listener、 filter、servlet 加载顺序及其详解
2012-08-23 11:09 757在项目中总会遇到一些关于加载的优先级问题,近期也同样遇到过 ... -
【转】web.xml中listener的作用及使用(转)
2012-08-23 11:07 817概述: Servlet监听器用于监听一些重要事件的发生, ... -
html中get和post的区别
2012-06-06 09:48 9531. get是从服务器上获取数据,post是向服务器传送数据。 ... -
【转】Java程序员的良药:应用程序的开发技巧
2012-05-11 18:04 712【IT168 技术】 假如你是一名Java开发者,正在开发 ... -
try-catch-finally与return的执行顺序
2011-11-16 17:30 1959写java程序经常碰到异常,try-catch-f ...
相关推荐
request.getParameter() 和request.getAttribute() 区别
request.setAttribute()和getAttribute()方法传递的数据只会存在于Web容器内部,在具有转发关系的Web组件之间共享。即request.getAttribute()方法返回request范围内存在的对象,而request.getParameter()方法是获取...
本篇文章小编为大家介绍,基于request.getAttribute与request.getParameter的区别详解。需要的朋友参考下
在后台通过Request取值为null,是因为只设置了id属性,而取值候用的是name属性,问题就出现在这里
// String methodName = request.getParameter("method"); // // //根据method属性的值调用相应的方法 // if("login".equals(methodName)){ // this.login(request,response); // }else if("register".equals(method...
String action request getParameter "action" ; Teacher t new Teacher ; t setUsername request getParameter "username" ; if "register" equals action { t set...
String name = request.getParameter("username"); String pwd =request.getPareameter("pwd"); 内部跳转: LoginServlet request.getRequestDispatcher("index.jsp").forward(request, resposne); 外部跳转: ...
A.request.getParameter(name) B.request.getParameter("name") C.request.getParameterValues(name) D.request.getParameterValues("name") 3.使用 response 对象进行重定向时,使用的是(c )方法。 A....
提交表单代码: ...-- 注意href和action都是写的完整的名称:项目名和资源路径名 --> <!-- 下面一句是get请求方式并在URL后面传值 --> 点击这里 <form action="/Web/AAServlet" method="pos
//得到书号和书本对象 int bookid =Integer.parseInt(request.getParameter("id")); Map, Book> books = (Map, Book>)request.getSession().getServletContext().getAttribute("books"); Book book = books....
//不管在什么情况下·有没有中文的接收我们必须设置他的request的setCharacterEncoding方法 ReplyDao replyDao =new ReplyDaoImpl(); int uId=Integer.parseInt(request.getParameter("uId")); int boardId=...
String url = request.getParameter("url"); URLEncoder.encode(URLDecoder.decode(url,"iso-8859-1"), "iso-8859-1"); session.setAttribute("redirectUrl",url); } else{ session.setAttribute(...
String whichsubmit request getParameter "whichsubmit" ; if whichsubmit null { HttpSession session request getSession ; Object loginer session getAttribute "loginer" ; ...
double rnumber=Double.valueOf(request.getParameter("rnumber")); HttpSession session = request.getSession(false); String cusername=(String) session.getAttribute("cusername"); ContentInfobiz ...
使用Request对象的getCookie()方法,执行时将所有客户端传来的Cookie对象以数组的形式排列,如果要取出符合需要的Cookie对象,就需要循环比较数组内每个对象的关键字。 例如: Cookie[] c = request.get...
String id=request.getParameter("id"); List<CartItem> items=(List)this.getServletContext().getAttribute("items"); CartItem item=null; for(CartItem i : items){ if(i.getId().equals(id)){ ...
String code = request.getParameter("code"); //取出生成的验证码(系统生成的) HttpSession session = request.getSession(); String rancode = (String)session.getAttribute("random"); if(code.equals(rancode))...
UserAccessToken token = (UserAccessToken) request.getSession().getAttribute("UserAccessToken"); if(null==token){ token = util.getAccessToken3(Constants.APPID, Constants.SECRET,code); ...
这既包括 servlet 又包括被编译成 servlet 的 JSP 页面 request是是代表与 Web 客户机发出的一个请求相关的对象和属性。一个请求可能跨越多个页面,涉及多个 Web 组件(由于 forward 指令和 include 动作的关系) ...
107、getParameter与 getAttribute的区别? 24 108、以下哪一个不是赋值符号? 25 109、以下哪个不是Collection的子接口? 25 110、.BufferedReader的父类是以下哪个? 25 112、div与span区别? 25 113、html的框架是...