日历表格完整代码:
<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%>
<%
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
<%@pageimport="java.text.SimpleDateFormat"%>
<%@pageimport="java.util.*"%>
<html>
<head>
<basehref="<%=basePath%>">
<title>MyJSP'index.jsp'startingpage</title>
<metahttp-equiv="pragma"content="no-cache">
<metahttp-equiv="cache-control"content="no-cache">
<metahttp-equiv="expires"content="0">
<metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
<metahttp-equiv="description"content="Thisismypage">
<!--
<linkrel="stylesheet"type="text/css"href="styles.css">
-->
</head>
<body>
<%!inti=1;
intalldays=0;//变量alldays记录本月的天数;
%>
<%!Datedate=newDate();%>
<%!SimpleDateFormatformat=newSimpleDateFormat("yyyy年MM月dd日");
SimpleDateFormatformat1=newSimpleDateFormat("MM");
SimpleDateFormatformat2=newSimpleDateFormat("dd");
Stringstr=format.format(date);//获取日期格式为:2018年03月15日;
Stringmm=format1.format(date);//获取月;
Stringdd=format2.format(date);//获取天;
Calendardate1=Calendar.getInstance();
intweekday=date1.get(Calendar.DAY_OF_WEEK_IN_MONTH)+1;
intfirstweek=date1.get(Calendar.DAY_OF_WEEK);//获取本月第一天星期几;
inttd=Integer.valueOf(dd)%7;
%>
<%if(mm.equals("01")||mm.equals("03")||mm.equals("05")||mm.equals("07")||mm.equals("08")||mm.equals("10")||mm.equals("12")){
alldays=31;
}
elseif(mm.equals("02")){
alldays=29;
}
else{
alldays=30;
}
%>
<%
intflagdate=1;
inta[][]=newint[5][7];
//intj=0,k=0;
for(intj=0;j<5;j++){
for(intk=0;k<7;k++){
if(j==0&&k<firstweek-1){
a[j][k]=0;
}
else{
if(flagdate<alldays+1){
a[j][k]=flagdate;
flagdate++;
}
}
}
}
%>
<tableborder="1"width="30%"align="center">
<tr>
<h1align="center"><%out.println(str);%>
</tr>
<divalign="center"><buttontype="button"><imgsrc="F:\MyWorkSpace\DateJsp\WebRoot\563481.png"width="30%"value="上个月"/></button>
<buttontype="button"><imgsrc="F:\MyWorkSpace\DateJsp\WebRoot\563482.png"width="30%"value="下个月"/></button>
</div>
<br>
<trbgcolor=#FFF68F>
<%for(i=1;i<8;i++){
%>
<td><%=i%></td>
<%
}%>
</tr>
<%
for(intj=0;j<5;j++){
%><tr><%
for(intk=0;k<7;k++){
if(a[j][k]!=0){
if(a[j][k]==Integer.valueOf(dd)){
%><tdbgcolor=#FF4500><%=a[j][k]%>
</td><%
continue;
}
%><tdbgcolor="#FFFFE0"><%=
a[j][k]
%>
</td><%
}
else{
%><tdbgcolor="#FFFFE0"></td><%
}
}
%></tr><%
}
%>
</table>
</body>
</html>

本文转载自中文网

本文转载自中文网
如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h55678.shtml