日历表格完整代码:
<%@ 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"> <%@page import="java.text.SimpleDateFormat"%> <%@page import="java.util.*"%> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</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"> --> </head> <body> <%! int i=1; int alldays=0;//变量alldays记录本月的天数; %> <%! Date date=new Date();%> <%! SimpleDateFormat format=new SimpleDateFormat("yyyy年MM月dd日"); SimpleDateFormat format1=new SimpleDateFormat("MM"); SimpleDateFormat format2=new SimpleDateFormat("dd"); String str=format.format(date);//获取日期格式为:2018年03月15日; String mm=format1.format(date);//获取 月; String dd=format2.format(date);//获取 天; Calendar date1=Calendar.getInstance(); int weekday=date1.get(Calendar.DAY_OF_WEEK_IN_MONTH)+1; int firstweek=date1.get(Calendar.DAY_OF_WEEK);//获取本月第一天星期几; int td=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; } else if(mm.equals("02")){ alldays=29; } else{ alldays=30; } %> <% int flagdate=1; int a[][]=new int[5][7]; //int j=0,k=0; for(int j=0;j<5;j++){ for(int k=0;k<7;k++){ if(j==0&&k<firstweek-1){ a[j][k]=0; } else{ if(flagdate<alldays+1){ a[j][k]=flagdate; flagdate++; } } } } %> <table border="1" width="30%" align="center"> <tr> <h1 align="center"><%out.println(str); %> </tr> <div align="center"><button type="button"><img src="F:\MyWorkSpace\DateJsp\WebRoot3481.png" width="30%" value="上个月"/></button> <button type="button"><img src="F:\MyWorkSpace\DateJsp\WebRoot3482.png" width="30%" value="下个月"/></button> </div> <br> <tr bgcolor=#FFF68F> <%for(i=1;i<8;i++){ %> <td><%=i %></td> <% }%> </tr> <% for(int j=0;j<5;j++){ %><tr><% for(int k=0;k<7;k++){ if(a[j][k]!=0){ if(a[j][k]==Integer.valueOf(dd)){ %><td bgcolor=#FF4500><%=a[j][k] %> </td><% continue; } %><td bgcolor="#FFFFE0"><%= a[j][k] %> </td><% } else{ %><td bgcolor="#FFFFE0"> </td><% } } %></tr><% } %> </table> </body> </html>
以上就是jsp日历表格怎么做的详细内容,
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)