Java determines whether the year is leap years

Source: Internet
Author: User


In t1.jsp, you set up a form, you can enter the year, commit to another action to perform the calculation,
If the calculation is a leap year, then jump to a1.jsp (show leap years), if it is common year jump to a2.jsp (show common year).

Requirements: The algorithm that calculates whether a leap year is needed is encapsulated into a tool class Myyear Isleap method.

In t1.jsp

<form action= "action.jsp" method= "POST" >
Please enter the year
<input type= "Text" name= "Year" >
<input type= "Submit" Name= "Submit" >
</form>

Tool Class 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;
}
}

In 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");
}
}

%>

In a1.jsp

${year} is common year

In a2.jsp

${year} is a leap year

Java determines whether the year is leap years

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.