程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> 在JSP網頁上實現月歷

在JSP網頁上實現月歷

編輯:關於JSP

在jsp(SUN企業級應用的首選)網頁上實現月歷

jsp(SUN企業級應用的首選)、月歷

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*,java.text.*" %>
<html>
<head>
<title>月歷</title>
</head>
<body >
<%!
 /*聲明變量*/
 String[] months = {"January", "February", "March", "April", "May", "June",
        "July", "August", "September", "October", "November", "December"};
 String[] months_cn = {"一月", "二月", "三月", "四月", "五月", "六月",
           "七月", "八月", "九月", "十月", "十一月", "十二月"};
 public final static int dom[] = {
         31, 28, 31, 30,
         31, 30, 31, 31,
         30, 31, 30, 31
 };
%>
<%
 /*處理事件*/
 boolean yyok = false;
 int yy = 0, mm = 0;
 String yyString = request.getParameter("year");
 if (yyString != null && yyString.length() >0) {
  try {
   yy=Integer.parseInt(yyString);
   yyok=true;
  }
  catch (NumberFormatException e) {
   out.println("年份不可用");
  }
  Calendar cal = Calendar.getInstance();
  if (!yyok)
   yy = cal.get(Calendar.YEAR);
  String mmString = request.getParameter("month");
  if (mmString == null) {
   mm = cal.get(Calendar.MONTH);
  }
  else {
   for (int i = 0; i < months.length; i++)
    if (months[i].equals(mmString)) {
     mm = i;
     break;
    }
  }
 }
%>
<form name="cal" method=post action="cal.jsp(SUN企業級應用的首選)">
 請選擇月份:
  <select name="month">
   <%
    /*初始化表單*/
   for (int i = 0; i < months.length; i++) {
    if (i == mm)
     out.print("<option selected value=January>");
    else
     out.print("<option value="+months[i]+">");
    out.print(months_cn[i]);
    out.print("</option>");
   }
   %>
  </select>
 <br>請輸入年份:
   <input type="text" size="5" name="year" value="<%=yy%>">&nbsp;&nbsp;
   <input type="submit" value="顯示">
</form>
<%
 int lead = 0;
%>
<table border="0" cellpadding="1" cellspacing="1" >
<tr height="20"><td colspan="7"><font color="#3399FF"><b><%= months[mm]%>  <%= yy%></b></font></td></tr>
<% GregorianCalendar calendar =  new GregorianCalendar(yy, mm ,1); %>
<tr><td><font color="#FF0000">Sun</font></td><td>Mon</td><td>Tue</td><td>Wed</td>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved