一个用JSP做的日历

1@ page language="java" import="java.util.*" 
1! String year;   
2  
3String month;   
4  
1 month=request.getParameter("month");   
2  
3year =request.getParameter("year");   
4  
 1<html>
 2<head>
 3<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
 4<title>日</title>
 5<script language="JavaScript">   
 6  
 7<!--   
 8  
 9function changeMonth()   
10  
11{   
12  
13var mm="calendar.jsp?month="+document.sm.elements[0].selectedIndex+"&year="   
14  
15+```
16=year
17```;   
18  
19window.open(mm,"_self");   
20  
21}   
22  
23//--></script>
24</head>   
25  

! String days[];

1  

days=new String[42];

for(int i=0;i&lt;42;i++)

{

days="";

}

1  

Calendar thisMonth=Calendar.getInstance();

if(month!=null&amp;&amp;(!month.equals("null")))

thisMonth.set(Calendar.MONTH, Integer.parseInt(month) );

if(year!=null&amp;&amp;(!year.equals("null")))

thisMonth.set(Calendar.YEAR, Integer.parseInt(year) );

year=String.valueOf(thisMonth.get(Calendar.YEAR));

month=String.valueOf(thisMonth.get(Calendar.MONTH));

thisMonth.setFirstDayOfWeek(Calendar.SUNDAY);

thisMonth.set(Calendar.DAY_OF_MONTH,1);

int firstIndex=thisMonth.get(Calendar.DAY_OF_WEEK)-1;

int maxIndex=thisMonth.getActualMaximum(Calendar.DAY_OF_MONTH);

for(int i=0;i<maxindex;i++) <body="" ```="" days[firstindex+i]="String.valueOf(i+1);" {="" }="">

   =year年  ``` =Integer.parseInt(month)+1

 1  
 2<table border="0" height="81" width="168">
 3<div align="center">
 4<tr>
 5<th bgcolor="#FFFF00" height="16" width="25"><font color="red">日</font>
 6</th>
 7<th bgcolor="#FFFF00" height="16" width="25">一</th>
 8<th bgcolor="#FFFF00" height="16" width="25">二</th>
 9<th bgcolor="#FFFF00" height="16" width="25">三</th>
10<th bgcolor="#FFFF00" height="16" width="25">四</th>
11<th bgcolor="#FFFF00" height="16" width="25">五</th>
12<th bgcolor="#FFFF00" height="16" width="25"><font color="green">六</font></th>
13</tr>   
14  

for(int j=0;j&lt;6;j++) {

1  
2<tr>   
3  

for(int i=j*7;i&lt;(j+1)*7;i++) {

 1  
 2<td align="ce   
 3  
 4nter" bgcolor="#C0C0C0" height="16" valign="middle" width="15%">
 5<a href="jump.jsp?year=```
 6=year
 7```&amp;month=```
 8=Integer.parseInt(month)+1
 9```&amp;d   
10  
11ate=```
12=days[i]
13```" target="main">```
14=days[i]
15```</a></td>   
16  

}

1  
2</tr>   
3  

}

 1  
 2</div>
 3</table>
 4<table border="0" height="20" width="168">
 5<tr>
 6<td width="30%"><select name="month" onchange="changeMonth()" size="1">
 7<option value="0">一月</option>
 8<option value="1">二月</option>
 9<option value="2">三月</option>
10<option value="3">四月</option>
11<option value="4">五月</option>
12<option value="5">六月</option>
13<option value="6">七月</option>
14<option value="7">八月</option>
15<option value="8">九月</option>
16<option value="9">十月</option>
17<option value="10">十一月</option>
18<option value="11">十二月</option>
19</select></td>
20<td width="28%"><input =year="" ```="" maxlength="4" name="year" size="4" type="text" value="```"/></td>
21<td>年</td>
22<td width="28%"><input type="submit" value="提交"/></td>
23</tr>
24</table>
25</form>
26<script language="JavaScript">   
27  
28<!--   
29  
30document.sm.month.options.selectedIndex=```
31=month
32```;   
33  
34  
35//-->   
36  
37</script>
38
39</maxindex;i++)></html>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus