Home  >  Article  >  Web Front-end  >  How to make jsp calendar table

How to make jsp calendar table

anonymity
anonymityOriginal
2019-05-29 15:06:023746browse

JSP全名为Java Server Pages,中文名叫java服务器页面,其根本是一个简化的Servlet设计,它是由Sun Microsystems公司倡导、许多公司参与一起建立的一种动态网页技术标准。JSP技术有点类似ASP技术,它是在传统的网页HTML(标准通用标记语言的子集)文件(*.htm,*.html)中插入Java程序段(Scriptlet)和JSP标记(tag),从而形成JSP文件,后缀名为(*.jsp)。 用JSP开发的Web应用是跨平台的,既能在Linux下运行,也能在其他操作系统上运行。

How to make jsp calendar table

日历表格完整代码:

<%@ 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 &#39;index.jsp&#39; 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\WebRoot\563481.png" width="30%" value="上个月"/></button>
    <button type="button"><img src="F:\MyWorkSpace\DateJsp\WebRoot\563482.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>

The above is the detailed content of How to make jsp calendar table. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to add css to htmlNext article:How to add css to html