分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

用jsp判断年份是润年还是平年

发布时间:2023-09-06 01:59责任编辑:沈小雨关键词:jsjsp

第一步创建一个JSP

<!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>Insert title here</title>
</head>
<body>
平年
</body>
</html>


第二步根据表单上的action跳转到另一个JSP中    注意我这里的MyYear是封装类 ,我的封装类在后面

<%
String a=request.getParameter("year");//请求获得网页里的year值
int year=Integer.parseInt(a);//把year值强转为int型

MyYear years=new MyYear();//实例化MyYear方法
if(years.isLeap(year)==true){//判断year值是否为润年
response.sendRedirect("a1.jsp");//是就跳转到a1.jsp中
}else{//否则
response.sendRedirect("a2.jsp");//跳转到a2.jsp
}
%>


创建a1.jsp

<!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>Insert title here</title>
</head>
<body>
闰年
</body>
</html>


创建a2.jsp

<!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>Insert title here</title>
</head>
<body>
平年
</body>
</html>


封装类

public boolean isLeap(int year){ //创建一个方法
boolean flag;//设置一个布尔值
if(year%4==0 || year%400==0 && year%100!=0){//判断是否为润年
flag=true;//是flag就设置为正确
}else{//否则是错误
flag=false;
}
return flag;//返回一个flag
}

用jsp判断年份是润年还是平年

原文地址:https://www.cnblogs.com/skjy/p/9165360.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved