没有合适的资源?快使用搜索试试~ 我知道了~
了解JSP中request属性的用法
需积分: 30 1 下载量 124 浏览量
2011-04-19
09:44:58
上传
评论
收藏 16KB DOCX 举报
温馨提示
试读
2页
很全面的了解request的属性和用法,叫你如何是使用request
资源推荐
资源详情
资源评论
了解 JSP 中 request 属性的用法
http://developer.51cto.com 2009-06-30 16:58 网络 builder 我要评论(0)
本文介绍 JSP 中 request 属性的用法,以及 request.getParameter() 和
request.getAttribute() 区别。
一、request.getParameter() 和 request.getAttribute() 区别
1.request.getParameter()取得是通过容器的实现来取得通过类似 post,get 等方
式传入的数据,request.setAttribute()和 getAttribute()只是在 web 容器内部流转,仅
仅是请求处理阶段。
2.request.getParameter()方法传递的数据,会从 Web 客户端传到 Web 服务器端,
代表 HTTP 请求数据。request.getParameter()方法返回 String 类型的数据。
request.setAttribute()和 getAttribute()方法传递的数据只会存在于 Web 容器内
部还有一点就是,HttpServletRequest 类有 setAttribute()方法,而没有
setParameter()方法。拿一个例子来说一下吧,假如两个 WEB 页面间为链接关系时,就
是说要从 1.JSP 链接到 2.JSP 时,被链接的是 2.JSP 可以通过 getParameter()方法来获得
请求参数.
假如 1.JSP 里有
1. <form name="form1" method="post" action="2.jsp">
2. 请输入用户姓名:<input type="text" name="username">
3. <input type="submit" name="Submit" value="提交">
4. </< SPAN>form>
的话在 2.JSP 中通过 request.getParameter("username")方法来获得请求参数
username:
< % String username=request.getParameter("username"); %>但是如果两
个 WEB 间为转发关系时,转发目的 WEB 可以用 getAttribute()方法来和转发源 WEB 共
享 request 范围内的数据,也还是说一个例子吧。有 1.JSP 和 2.JSP
1.JSP 希望向 2.JSP 传递当前的用户名字,如何传递这一数据呢?先在 1.JSP 中调用如
下 setAttribute()方法:
5. <%
6. String username=request.getParameter("username");
7. request.setAttribute("username",username);
8. %>
9. <jsp:forward page="2.jsp" />
10. 在 2.jsp 中通过 getAttribute()方法获得用户名字:
11. <% String username=(String)request.getAttribute("username"); %>
二、request.getAttribute()与 request.setAttribute()
资源评论
raomi
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功