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