欢迎光临
我们一直在努力

在JSP网页上实现月历-JSP教程,Jsp/Servlet

建站超值云服务器,限时71元/月

在jsp网页上实现月历

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>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 在JSP网页上实现月历-JSP教程,Jsp/Servlet
分享到: 更多 (0)

相关推荐

  • 暂无文章