小编提示:运行时请将全角符号<>替换为半角符号<>
java编程学习:自己diy一个jsp日历,这是源代码,只要运行一下就知道结果了。
<%@ page contenttype="text/html; charset=gb2312" language="java" import="java.sql.*" errorpage="" %>
<%@ page language="java" import="java.util.*" %>
<%! string days[]; %>
<body>
<%
days=new string[42];
for(int i=0;i<42;i++)
{
days[i]="";
}
%>
<%
gregoriancalendar currentday = new gregoriancalendar();
int today=currentday.get(calendar.day_of_month);
int month=currentday.get(calendar.month);
int year= currentday.get(calendar.year);
out.println(year+"年"+ (month+1)+"月"+today+"日");
calendar thismonth=calendar.getinstance();
thismonth.set(calendar.month, month );
thismonth.set(calendar.year, year );
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);
}
%>
<table border="0" width="168" height="81">
<div align=center>
<tr>
<th width="25" height="16" ><font color="red">日</font>
</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" ><font color="red">六</font></th>
</tr>
<% for(int j=0;j<6;j++) { %>
<tr>
<% for(int i=j*7;i<(j+1)*7;i++) { %>
<td width="15%" height="16" valign="middle" align="center">
<%if((i-firstindex+1)==today){
%>
<font color="red"><%=days[i]%></font>
<%
} else {
%>
<%=days[i]%>
<%
}
%>
</td>
<% } %>
</tr>
<% } %>
</div>
</table>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器