在JSP网页上实现月历
在jsp(SUN企业级应用的首选)网页上实现月历
jsp(SUN企业级应用的首选)、月历
<%@ 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(SUN企业级应用的首选)">
请选择月份:
<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%>">
<input type="submit" value="显示">
相关新闻>>
- 发表评论
-
- 最新评论 更多>>