• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

在JSP网页上实现月历

发布: 2007-7-04 13:34 | 作者: admin | 来源:  网友评论 | 查看: 9次 | 进入软件测试论坛讨论

领测软件测试网

JSP、月历

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*,java.text.*" %>
<html>
<head>
<title>月历</title>
</head>
<body style="font-size:12px">
<%!
/*声明变量*/
String[] months = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
String[] months_cn = {"一月", "二月", "三月", "四月", "五月", "六月",
"七月", "八月", "九月", "十月", "十一月", "十二月"};
public final static int dom[] = {
31, 28, 31, 30,
31, 30, 31, 31,
30, 31, 30, 31
};
%>
<%
/*处理事件*/
boolean yyok = false;
int yy = 0, mm = 0;
String yyString = request.getParameter("year");
if (yyString != null && yyString.length() >0) {
try {
yy=Integer.parseInt(yyString);
yyok=true;
}
catch (NumberFormatException e) {
out.println("年份不可用");
}
Calendar cal = Calendar.getInstance();
if (!yyok)
yy = cal.get(Calendar.YEAR);
String mmString = request.getParameter("month");
if (mmString == null) {
mm = cal.get(Calendar.MONTH);
}
else {
for (int i = 0; i < months.length; i++)
if (months[i].equals(mmString)) {
mm = i;
break;
}
}
}
%>
<form name="cal" method=post action="cal.jsp">
请选择月份:
<select name="month">
<%
/*初始化表单*/
for (int i = 0; i < months.length; i++) {
if (i == mm)
out.print("<option selected value=January>");
else
out.print("<option value="+months[i]+">");
out.print(months_cn[i]);
out.print("</option>");
}
%>
</select>
<br>请输入年份:
<input type="text" size="5" name="year" value="<%=yy%>">&nbsp;&nbsp;
<input type="submit" value="显示">
</form>
<%
int lead = 0;
%>
<table border="0" cellpadding="1" cellspacing="1" style="font-size:12px">
<tr height="20"><td colspan="7"><font color="#3399FF"><b><%= months[mm]%> <%= yy%></b></font></td></tr>
<% GregorianCalendar calendar = new GregorianCalendar(yy, mm ,1); %>
<tr><td><font color="#FF0000">Sun</font></td><td>Mon</td><td>Tue</td><td>Wed</td>
<td>Thu</td><td>Fri</td><td><font color="#FF0000">Sat</font></td></tr>
<%
/*下面是显示月历的代码*/
lead = calendar.get(Calendar.DAY_OF_WEEK)-1;
int dayInMonth = dom[mm];
if (calendar.isLeapYear(calendar.get(Calendar.YEAR)) && mm == 1)
++dayInMonth;
out.print("<tr>");
for(int i = 0; i < lead; i++) {
out.print("<td>&nbsp;</td>");
}
for(int i = 1; i <= dayInMonth; i++) {
if ((i+lead) % 7 == 0 || (i+lead) % 7 == 1)
out.print("<td align=\"center\"><font color=\"#FF0000\">"+i+"</font></td>");
else
out.print("<td align=\"center\">"+i+"</td>");
if ((lead+i) % 7 == 0) {
out.print("</tr></tr>");
}
}
out.print("</tr>");
%>
</table>
</body>
</html>


文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网