getPropertyname="guess"property="guessNumber"/>
<%Stringstr=response.encodeRedirectURL("guess.jsp");
%>
"method=post>
再输入你的猜测
<%Stringstr1=response.encodeRedirectURL("getNumber.jsp");
%>
"method="post"name="f">
例3:
显示日历时间:
JSPCalendar.java:
packagecalendar.bean
importjava.util.*;
publicclassJSPCalendar
{Calendarcalendar=null;
intyear,dayOfMonth,dayOfYear,weekOfYear,
weekOfMonth,dayOfWeek,hour,minute,second;
Stringday,date,time;
publicJSPCalendar()
{calendar=Calendar.getInstance();
Datetime=newDate();
calendar.setTime(time);
}
//获取年份:
publicintgetYear()
{returncalendar.get(Calendar.YEAR);
}
//获取月,进行格式处理:
publicStringgetMonth(){
intm=1+calendar.get(Calendar.MONTH);
Stringmonths[]={"1","2","3","4","5","6","7","8","9","10","11","12"};
if(m>12)
return"0";
returnmonths[m-1];
}
//获取星期几,进行格式处理:
publicStringgetDay()
{intn=getDayOfWeek();
Stringdays[]={"日","一","二","三","四","五","六"};
if(n>7)
return"星期?
";
returndays[n];
}
//获取:
年、月、日
publicStringgetDate()
{returngetYear()+"/"+getMonth()+"/"+getDayOfMonth();
}
publicStringgetTime()//获取:
时:
分:
秒
{returngetHour()+":
"+getMinute()+":
"+getSecond();
}
publicintgetDayOfMonth()//获取当前时间是一月中的哪一天
{returncalendar.get(Calendar.DAY_OF_MONTH);
}
publicintgetDayOfYear()//获取当前时间是一年中的哪一天
{returncalendar.get(Calendar.DAY_OF_YEAR);
}
publicintgetWeekOfYear()//获取当前时间是一年中的哪个星期
{returncalendar.get(Calendar.WEEK_OF_YEAR);
}
publicintgetWeekOfMonth()//获取当前时间是一年中的哪个星期
{returncalendar.get(Calendar.WEEK_OF_MONTH);
}
publicintgetDayOfWeek()//获取当前时间是一周中的哪一天
{returncalendar.get(Calendar.DAY_OF_WEEK)-1;
}
publicintgetHour()//获取小时
{returncalendar.get(Calendar.HOUR_OF_DAY);
}
publicintgetMinute()//获取分钟
{returncalendar.get(Calendar.MINUTE);
}
publicintgetSecond()//获取秒
{returncalendar.get(Calendar.SECOND);
}
}
显示日历时间的页面(效果如图6.33所示)
calendar.jsp:
<%@pagecontentType="text/html;charset=GB2312"%>
<%@pageimport="calendar.bean.JSPCalendar"%>