日期:2014-05-17  浏览次数:20855 次

日历的问题
大概叙述下问题。我设置了一个页面 12个月在上面可以选择 不同月份天数不同,这个我通过servlet实现了,现在有个问题就是处理每个月开始的时候星期不同的问题,这个问题处理好像没什么头绪。以前我用java也实现过日历 那时候是通过控制空格输出的 但是好像放在web下比较繁琐

JSP代码贴下

<form method="post" action="check">
<table border="0" width="100%" height="81" align=center>
&nbsp;&nbsp;&nbsp;2012年&nbsp;&nbsp;{month}月
<div align=center>
<tr>
  <%for(int i=1;i<=12;i++){%>
  <td colspan="3">
  <%request.setAttribute("month", i); %>
  <a href="check?month=${month}" }> <%=i%>月</a>
  </td>
  <%}%>
</tr>
<tr>
</table>
<table border="0" width="100%" height="81" align=center>
<div align=center>
<tr>
<th width="25" height="16">日</th>
<th width="25" height="16">一</th>
<th width="25" height="16">二</th>
<th width="25" height="16">三</th>
<th width="25" height="16">四</th>
<th width="25" height="16">五</th>
<th width="25" height="16">六</th>
</tr>
<%if(maxIndex!=null){%><!-- maxIndex的判断 -->



<% for(int countj=0;countj<6;countj++){%>
<tr>
<% for(int counti=countj*7;counti<(countj+1)*7;counti++){%>
<%if(counti<=maxIndex-1){%><!-- if开始 -->
<td width="15%" height="16" bgcolor="#C0C0C0" valign="middle" align="center">
<%=counti+1%></td>

<%}%>
<%}%> <!-- 第一个for循环 -->
</tr>
<%}%><!-- 第二个for循环 -->
</div>
</table>
</form>


<%}else{%><!-- maxIndex的判断结束 -->
</div>
</table>
</form>
<%="请选择月份!"%>
<%}%>

   
  </body>
</html>


check是servlet处理不同的月份有不同maxIndex(这个是最大天数)




------解决方案--------------------
直接从网上下载一个JS的日历控件吧。像这种东西没必要使用Java去实现。
------解决方案--------------------
还是用别人写好的日历把,推荐my97,官网提供了例子和下载。


http://www.my97.net/dp/index.asp
------解决方案--------------------
你们的老师伤不起啊。。。