⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lookupsign.java

📁 EJB最新技术开发指南源代码
💻 JAVA
字号:
package com.ibm.ivj.wte.samples.signs;

// Licensed Material - Property of IBM 
// (C) Copyright IBM Corp. 2000 - All Rights Reserved 
// 
// DISCLAIMER: 
// The following [enclosed] code is sample code created by IBM 
// Corporation.  This sample code is not part of any standard IBM product 
// and is provided to you solely for the purpose of assisting you in the 
// development of your applications.  The code is provided 'AS IS', 
// without warranty or condition of any kind.  IBM shall not be liable for any damages 
// arising out of your use of the sample code, even if IBM has been 
// advised of the possibility of such damages.

import javax.servlet.http.*;
import java.util.*;
/**
 * Insert the type's description here.
 * Creation date: (05/24/2000 11:52:36 AM)
 * @author: Administrator
 */
public class LookupSign extends HttpServlet {
private static final String copyright = 
	"(c) Copyright IBM Corporation 2000.";

/**
 * Insert the method's description here.
 * Creation date: (05/24/2000 11:53:39 AM)
 * @param request javax.servlet.http.HttpServletRequest
 * @param response javax.servlet.http.HttpServletResponse
 * @exception javax.servlet.ServletException The exception description.
 * @exception java.io.IOException The exception description.
 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {

	boolean validInput = true;
	int 	dd = 1;
	int 	mm = 1;
	String[] month = {"January", "February", "March", "April", "May", "June",
					"July", "August", "September", "October", "November", "December"};

	
	// Get the input parameters
	try {
		dd = Integer.parseInt(request.getParameter("dd"));
		mm = Integer.parseInt(request.getParameter("mm"));
	} catch (java.lang.NumberFormatException ex) {
		validInput = false;
	}	

	// Perform date validation
	if (validInput) {
		if ((mm >= 1) && (mm <= 12)) {
			if (mm == 2) {
				if ((dd < 1) || (dd > 29)) {
					validInput = false;
				}
			} else if ((mm == 1) || (mm == 3) || (mm == 5) || (mm == 7) || 
					  (mm == 8) || (mm == 10) || (mm == 12)) { 
				if ((dd < 1) || (dd > 31)) {
					validInput = false;
				}
			} else {
				if ((dd < 1) || (dd > 30)) {
					validInput = false;
				}
			}
		} else {
			validInput = false;
		}
	}

	// Display result
	response.setContentType("text/html");
	java.io.PrintWriter out =response.getWriter();
	out.println("<HTML>");
	out.println("<HEAD><TITLE>Signs of the Zodiac</TITLE></HEAD>");
	out.println("<BODY BGCOLOR=#C0C0C0>");
	out.println("<H1>Signs of the Zodiac</H1><P><P>");

//	Uncomment the following 3 lines to find out the sign for today.	
//	Calendar cal=Calendar.getInstance();
//	cal.setTime(new Date());
//	out.println("<H2>The sign for today is " + getSign(cal.get(Calendar.MONTH)+1, cal.get(Calendar.DAY_OF_MONTH)) + "</H2><P>");

	if (validInput) {
		out.println("<H2>The sign for " + month[mm - 1] + " " + dd + " is " + getSign(mm, dd) + "</H2><P>");
	} else {
		out.println("<H2>Invalid Input Date</H2><P>");
	}
	out.println("<A HREF=\"/JSP/index.html\">Back to the Samples Index Page</A>");
	out.println("</BODY></HTML>");
	
}
/**
 * Insert the method's description here.
 * Creation date: (05/24/2000 12:17:13 PM)
 * @return java.lang.String
 * @param mmdd int
 */
public String getSign(int mm, int dd) {
	String[] sign = {"Capricorn", "Aquarius", "Pisces", "Aries", "Taurus", "Gemini",
					"Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius",
					"Capricorn"};
	int[] signdate = {119, 218, 320, 419, 520, 621, 722, 822, 922, 1023,
					1121, 1221, 1231};

	
	int mmdd = mm * 100 + dd;
	int i = 0;
	while ((i <= 12) && (mmdd > signdate[i])) {
		i++;
	}
	return sign[i];
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -