- 174
- 0
- 约4千字
- 约 5页
- 2017-07-27 发布于重庆
- 举报
JSP内置对象实验
JSP内置对象实验
一、实验目的
1.掌握 JSP 内置对象:request、response、session、application、out等。
2.掌握 JSP 内置对象的使用方法。
二:实验
1:编写一个简单的留言薄,写入留言提交后显示
输出内容:
2:设计一添加、删除 session 变量及其值的程序
%@ page language=java contentType=text/html; charset=UTF-8
pageEncoding=UTF-8 import=java.util.*%
!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN /TR/html4/loose.dtd
html
head
meta http-equiv=Content-Type content=text/html; charset=UTF-8
titleInsert title here/title
/head
body
center
font size=5 color=#DB1260 管理Session变量 /font BR
HR
BR
%
if (request.getParameter(AddValue) != null) {
session.setAttribute(request.getParameter(NameField),
request.getParameter(ValueField));
} else if (request.getParameter(DeleteValue) != null) {
session.removeAttribute(request.getParameter(NameField));
}
%
center
table border=1 cellspacing=2 cellpadding=5 width=400 bgcolor=#EEEEEE
th colspan=2Session/th
tr
tdB变量名/B/td
tdB变量值/B/td
/tr
%
Enumeration sessionNames = session.getAttributeNames();
String name;
while (sessionNames.hasMoreElements()) {
name = (String) sessionNames.nextElement();
%
tr
td%=name%/td
td%=(String) session.getAttribute(name)%/td
/tr
%
} // end of while loop for session names
%
/table
/center
p
form method=post name=SessionTest action=
center
table border=0 cellspacing=2 cellpadding=5 width=400
th变量名/th
th变量值/th
tr
tdinput type=text name=NameField/td
tdinput type=text name=ValueField/td
/tr
tr
td colspan=2 align=centerinput type=submit value=添加
name=AddValue input type=submit value=删除
name=DeleteValue/td
/tr
/table
/center
/form
/center
/body
/html
3:使用application对象编写一个网页计数器
4:编写一个页面计数器,刷新不增加计数
提示:
1:使用cookie:服务器上的文件保存了访问次数用户访问后cookie并更新访问次数文件。刷新不增加次数。%@ page language=java contentType=text/html; charset=utf-8
pageEncoding=utf-8%
!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN /TR
您可能关注的文档
最近下载
- 省考公务员-贵州-行政职业能力测验-第二章言语理解与表达-第一章逻辑填空-.docx VIP
- 2025福建闽投永安抽水蓄能有限公司招聘40人(公共基础知识)测试题附答案解析.docx VIP
- 2024年西安交通大学少年班初试数学真题及解析 .pdf VIP
- 三菱帕杰罗维修资料-结构图.pdf
- 习概习题汇总.docx VIP
- 急性肾盂肾炎医师查房记录.docx VIP
- 矿山生态保护修复验收规范.pdf VIP
- 2024-2025学年浙江省杭州市滨江区六年级(上)期末数学试卷(含答案).pdf VIP
- 中国古典名著《鬼谷子》.pdf VIP
- 大学物理通用教程_电磁学(第二版)陈秉乾习题解答.pdf
原创力文档

文档评论(0)