日期:2014-05-19  浏览次数:20836 次

jsp日历...小问题
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
   
  <title>日历</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<!-- 声明变量 -->
<%!
String year;//年
String month;//月
String days[];//日历表数组
%>
<%
//获得客户表单参数
month = request.getParameter("month");
year = request.getParameter("year");
%>
<script type="text/javascript">
function changeMonth(){
var mm = "calendar.jsp?month="+document.sm.elements[0].selectedIndex+"&year="+<%=year%>;
window.open(mm,"_self");
}
</script>
  </head>
  
  
  <%
  //每个月的日历为6行*7列
  days = new String[42];
  //日历表数组初始化
  for(int i = 0 ; i<42;i++){
  days[i]="";
  }
  //获得Calendar类的一个实例
  Calendar thisMonth = Calendar.getInstance();
  //设置月份
  if(month !=null && (!month.equals("null"))){
  thisMonth.set(Calendar.MONTH,Integer.parseInt(month));
  }
  //设置年份
  if(year !=null && (!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++){
  days[firstIndex+i] = String.valueOf(i+1);
  }
  //日历表数组值设置完毕
  %>
  <body>
  <div align="center">
  <form name="sm" method="post" action="calendar.jsp">
  <%=year %>年 <%=Integer.parseInt(month)+1 %>月
  <table border="0" height="90">
  <!-- 日历表的第一行。显示日期 -->
  <TR>
  <td width="25" headers="16" bgcolor="#ffff00"><font color="red">日</font></td>
  <td width="25" headers="16" bgcolor="#ffff00">一</td>
  <td width="25" headers="16" bgcolor="#ffff00">二</td>
  <td width="25" headers="16" bgcolor="#ffff00">三</td>