关于request.setAttribute多页传值,多页取值
2016-03-14 11:08
369 查看
request的setAttribute方法确实能够多页传值和多页取值的,因为request完成的是服务器跳转,在这期间所有设置的内容会被保存下来。下面的例子包含4个页面,1page.jsp和2page.jsp完成的是页面多次传值,3page.sjp和4page.jsp完成的是页面多次取值,直到页面显示出来,url一直是1page.jsp,说明这是服务器跳转。
1page.jsp
2page.jsp
3page.jsp
4page.jsp
1page.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> </head> <% request.setAttribute("name","zhangsan"); %> <body> <jsp:forward page="2page.jsp"/> </body> </html>
2page.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> </head> <body> <jsp:forward page="3page.jsp"/> </body> </html>
3page.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> </head> <body> <%=request.getAttribute("name")%> <jsp:forward page="4page.jsp"/> </body> </html>
4page.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> </head> <body> <%=request.getAttribute("name")+" in 4page.jsp"%> </body> </html>
相关文章推荐
- request.getParameter()与request.setAttribute()的区别
- HDU 5288 OO’s Sequence
- Effective Java Second Edition --- Builder Pattern
- Druid连接池简单入门配置
- UIScrollerView循环滚动,加定时器和pageControl
- ligerUIGrid自适应BUG的解决方法
- UITableView优化技巧
- Qt使用教程之使用Qt Quick UI表单(六)
- HDU 5297 Y sequence 容斥 迭代
- UIGestureRecognizer 手势识别
- iOS-UITableView图解
- getpwuid()函数,getpgrgid()函数()
- iOS本地通知推送使用:UILocalNotification
- setuid()函数,setgid()函数,getpriority()函数,setpriority()函数,nice()函数
- uestc 482 Charitable Exchange 广搜+优先队列优化
- 创建透明的UIToolbar
- semantic-ui使用gulp执行build-css报错
- UITableView的数据源(dataSource)
- Android Studio Preview 报错 org.jetbrains.android.uipreview.RenderingException
- 《iOS Human Interface Guidelines》——Page View Controller