JSP第四章课后题答案和实验报告

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

第四章实验报告

4.7.1 实现日历

(1)日历bean,CalcendarBean.java 实现年、月、日等相关属性的设置和获取,代码如下:package beans;

import java.util.*;

public class CalcendarBean{

Calendar calendar = null;

int

year,dayOfMonth,dayOfYear,weekOfYear,weekOfMonth,dayOfWeek,hour,minute,second;

private String day;

String date;

String time;

public CalcendarBean(){

calendar=Calendar.getInstance();

Date time = new Date();

calendar.setTime(time);

}

public int getYear()

{return calendar.get(Calendar.YEAR);}

public String getMonth(){

int m=1+calendar.get(Calendar.MONTH);

String months[]={"1","2","3","4","5","6","7","8","9","10","11","12"};

if (m>12)

return "0";

return months[m+1];

}

public String getDay(){

int n = getDayOfWeek();

String days[]={"日","一","二","三","四","五","六"};

if (n>7)

return "星期?";

return days[n];

}

public String getDate()

{return getYear() + "/" + getMonth() + "/" + getDayOfMonth();}

public String getTime()

{return getHour() + ":" + getMinute() + ":" + getSecond();}

public int getDayOfMonth()

{return calendar.get(Calendar.DAY_OF_MONTH);}

public int getDayOfYear()

{return calendar.get(Calendar.DAY_OF_YEAR);}

public int getWeekOfYear()

{return calendar.get(Calendar.WEEK_OF_YEAR);}

public int getWeekOfMonth()

{return calendar.get(Calendar.WEEK_OF_MONTH);}

public int getDayOfWeek()

{return calendar.get(Calendar.DAY_OF_WEEK)-1;}

public int getHour()

{return calendar.get(Calendar.HOUR_OF_DAY);}

public int getMinute()

{return calendar.get(Calendar.MINUTE);}

public int getSecond()

{return calendar.get(Calendar.SECOND);}

}

(2)日历的显示由calendar.jsp 通过调用javabean来实现显示,代码如下:

<%@ page contentType="text/html;charset=GB2312" %>

<%@ page import="beans.CalcendarBean" %>

星期


当前时间为


今天是今年的第


本周是今年的第


本周是本月的第

(3)实现日历显示:

显示结果 4.7.1-1

4.7.2实现留言板

(1)留言板javabean,NoteBean.java主要实现作者、标题、和他们的相关属性的设置和获取,代码如下:

package beans;

public class NoteBean{

public String title;

public String author;

public String content;

相关文档
最新文档