码迷,mamicode.com
首页 > 编程语言 > 详细

java判断年份是否为闰年

时间:2018-06-11 11:06:33      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:pos   turn   方法   dir   end   EAP   string   lse   jsp   


在t1.jsp 中,设置一个表单,可以输入年份,提交到另外一个action进行计算,
如果算出来是闰年,那么就跳转到a1.jsp(显示闰年),如果是平年就跳转到a2.jsp(显示平年)。

要求:需要把计算是否闰年的算法,封装到一个工具类MyYear中isLeap方法中。

t1.jsp中

<form action="action.jsp" method="post">
请输入年份
<input type="Text" name="Year">
<input type="submit" name="submit">
</form>

工具类MyYear中

private int year;

public int getYear() {
return year;
}

public void setYear(int year) {
this.year = year;
}
public boolean isyear(){
if(year%4==0&&year%100!=0||year%400==0){
return true;
}else{
return false;
}
}

action.jsp中

<%
MyYear my=new MyYear();
String year=request.getParameter("Year");
int y=Integer.parseInt(year);
if(Character.isLowerCase(y)){
response.sendRedirect("t1.jsp");
}else{
my.setYear(y);
session.setAttribute("year",year);
if(my.isyear()){
response.sendRedirect("a2.jsp");
}else{
response.sendRedirect("a1.jsp");
}
}

%>

a1.jsp中

${year}是平年

a2.jsp中

${year}是闰年

java判断年份是否为闰年

标签:pos   turn   方法   dir   end   EAP   string   lse   jsp   

原文地址:https://www.cnblogs.com/zym2000/p/9165413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!