Jsp頁面+Java代碼判斷是否爲閏年

由客戶端輸入一個數,判斷是否爲閏年html

這是JSP頁面(給客戶端提供操做的頁面)

<%
@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="com.liaoyuanping.action.isLeap" %> --這是引用java代碼中的isLeap類方法 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>首頁</title> </head> <body> <form action="Test_action.jsp"> 請輸入年份:<input type="text" name="txtYear" id="txtYear"> <input type="submit" name="btnsub" id="btnsub" value="判斷"> </form> </body> </html>

在同一個項目下的src下建立一個名爲 com 的包,再建立一個isLeap類java

這是Java代碼中的isLeap方法
package
com.liaoyuanping.action; public class isLeap { private int year; public int getYear() { return year; } public void setYear(int year) { this.year = year; } public boolean isLeapYear(){ return(( year%100!=0 && year%4==0 || year%400==0)?true:false); } }

最後選擇整個項目右鍵選擇Run As --> Run on Server 運行,在瀏覽器頁面打開 瀏覽器

相關文章
相關標籤/搜索