编程开发 > JSP > 文章内容

jsp工作总结(10)

2016-10-4编辑:sunny
动态日历****************************
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="errorPage.jsp" %>
<%@ page language="java" import="java.util.*"%><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>jsp日历</title><%try{%>
<%String year=request.getParameter("year");
String month=request.getParameter("month");%>
<script Language="javaScript"><!--
function Monthchange() 
{var nowMonth="calendar.jsp?month="+document.yearmonth.elements[0].selectedIndex+"&year="+<%=year%>;
window.open(nowMonth,"_self");}//--></script></head>
<%String days[];days=new String[42];for(int counti=0;counti<42;counti++)
{days[counti]="";}%><%Calendar thisMonth=Calendar.getInstance();
if(month!=null&&(!month.equals("")))
thisMonth.set(Calendar.MONTH,Integer.parseInt(month));
if(year!=null&&(!year.equals("")))thisMonth.set(Calendar.YEAR,Integer.parseInt(year));
int maxIndex=0;year=String.valueOf(thisMonth.get(Calendar.YEAR));
month=String.valueOf(thisMonth.get(Calendar.MONTH));
if(month.equals("0")||month.equals("2")||month.equals("4")||month.equals("6")||month.equals("7")||month.equals("9")||month.equals("11"))
maxIndex=31;
if(month.equals("3")||month.equals("5")||month.equals("8")||month.equals("10"))
maxIndex=30;if(month.equals("1"))maxIndex=28;
thisMonth.setFirstDayOfWeek(Calendar.SUNDAY);thisMonth.set(Calendar.DAY_OF_MONTH,1);
int firstIndex=thisMonth.get(Calendar.DAY_OF_WEEK)-1;
for(int counti=0;counti<maxIndex;counti++){
days[firstIndex+counti]=String.valueOf(counti+1);}%><body>
<h3><center><form name="sm"method="post"action="calendar.jsp">
&nbsp;&nbsp;&nbsp;<%=year%>年&nbsp;&nbsp;<%=Integer.parseInt(month)+1%>月
<table border="0"width="168"height="81"><div align=center><tr>
<th width="25"height="16"bgcolor="#ffff00"><font color="red">日</font></th>
<th width="25"height="16"bgcolor="#ffff00">一</font></th>
<th width="25"height="16"bgcolor="#ffff00">二</font></th>
<th width="25"height="16"bgcolor="#ffff00">三</font></th>
<th width="25"height="16"bgcolor="#ffff00">四</font></th>
<th width="25"height="16"bgcolor="#ffff00">五</font></th>
<th width="25"height="16"bgcolor="#ffff00"><font color="green">六</font></th></tr>
<%for(int countj=0;countj<6;countj++){%><tr>
<% for(int counti=countj*7;counti<(countj+1)*7;counti++){%>
<td width="15%"height="16"bgcolor="#0066FF"valign="middle"align="center">
<%=days[counti]%></td><%}%></tr><%}%></div></table>
<table border="0"width="168"height="20"><tr>
<td width=30%><select name="month"size="1"onchange="changeMonth()">
<option value="0">一月</option><option value="1">二月</option>
<option value="2">三月</option><option value="3">四月</option>
<option value="4">五月</option><option value="5">六月</option>
<option value="6">七月</option><option value="7">八月</option>
<option value="8">九月</option><option value="9">十月</option>
<option value="10">十一月</option><option value="11">十二月</option></select></td>
<td width=28%><input type=text name="year"value=<%=year%> size=4 maxlength=4></td>
<td>年</td><td width=28%><input type=submit value="刷新"></td>
</tr></table></form></center><script language="JavaScript">
<!--
document.sm.month.options.selectedIndex=<%=month%>;
-->
</script></body></html><%}catch(Exception e){
%>输入的为非数字,请重新输入<%}%>
jsp工作总结(6)

热点推荐

登录注册
触屏版电脑版网站地图