第6章动态页面和用户会话.doc
文本预览下载声明
第6章 动态页面和用户会话
HYPERLINK 53:8488/jsp/JSPChapter6.htm \l s1#s1 6 HYPERLINK 53:8488/jsp/JSPChapter6.htm \l s1#s1 .1 HYPERLINK \l s1创建动态的内容HYPERLINK \l s26.2 用户会话跟踪
6.1 创建动态的内容
动态网页的动态主要是指:
根据时间的动态;
根据用户类型的动态;
根据用户定义信息的动态;
根据用户所述地区的动态;
根据数据库内容的动态;
6.1.1 根据时间的动态
教材例程6-1,根据时间动态产生页面, HYPERLINK :8080/ch6/dynamic_time.jsp \t _blank ch6\dynamic_time.jsp
%@ page language=java contentType=text/html;charset=gb2312%
% java.util.Date now=new java.util.Date();
? month=now.getMonth();
? System.out.println(month);
? bgcolor=;
? switch(month)
?????{
?????? case(1):bgcolor=blue;break;
??????? case(2):bgcolor=eeccff;break;
?????? case(3):bgcolor=99cfdf;break;
?????? case(4):bgcolor=34ccff;break;
?????? case(5):bgcolor=4eccff;break;
?????? case(6):bgcolor=562342;break;
?????? case(7):bgcolor=dfe421;break;
?????? case(8):bgcolor=34ff00;break;
?????? case(9):bgcolor=yellow;break;
?????? case(10):bgcolor=green;break;
?????? case(11):bgcolor=9933ff;break;
?????? case(12):bgcolor=e40022;
???? }
%
body bgcolor=%=bgcolor%
hr欢迎您!现在的时间是:%=now.toLocaleString()%
/body
6.1.2 根据用户类型的动态
教材例程6-2,根据用户类型动态产生页面, HYPERLINK :8080/jspdev/title.jsp \t _blank jspdev\title.jsp
%@ page contentType=text/html; charset=gb2312 %
!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
html
head
titleUntitled Document/title
meta http-equiv=Content-Type content=text/html; charset=gb2312
/headLINK href=hellking.css type=text/css rel=stylesheet
?
body
%
?????? ? boolean isLog=false;
?????? ?// out.println(session.getAttribute(isLog));
?????? ?try
?????? ?{
?????? ? isLog=((String)session.getAttribute(isLog)).equals(1);
?????? ?}
?????? ?catch(Exception e)
?????? ?{
?????? ?? //out.println(e);
?????? ?}
%
table width=842 align=center cellpadding=3 cellspacing=1 class=tableborder1
?? tr
?? td width=832 class=tablebody2::
?? a href=index.jsp target=_top首页/a
? ?a href=index.jsp target=_top邮件/a
?? a href=shop/searchForm.html target=mainFrame商品搜索/a
?? a href=/jspdev/servlet/forumservlet?jumpPage=1 t
显示全部