Integer my_int=new Integer(0); int year=my_int.parseInt(stryear); int month=my_int.parseInt(strmonth); int day=my_int.parseInt(strday); 改成 int year = Integer.parseInt(stryear); int month = Integer.parseInt(strmonth); int day = Integer.parseInt(strday);
<html> <head> <title>test</title> </head> <body> <% String stryear=request.getParameter("year"); String strmonth=request.getParameter("month"); String strday=request.getParameter("day"); Integer my_int=new Integer(0); if (stryear==null) stryear="2004"; if (strmonth==null) strmonth="4"; if (strday==null) strday="18"; int year=my_int.parseInt(stryear); int month=my_int.parseInt(strmonth); int day=my_int.parseInt(strday); boolean haserror=false; String errormsg=""; if(year<1800||year>3000) { haserror=true; errormsg=" <li>error! year must be in 1800~2001!</li>"; } if(month>12||month<1) {haserror=true; errormsg+=" <li>error! month must be in 1~12!</li>"; } int maxDays=31; if(month==4||month==6||month==9||month==11) {maxDays=30; } else if(month==2) {if (year%4>0) {maxDays=28; }else if(year%100==0&&year%400>0) {maxDays=28; }else{ maxDays=29;} } if(!(day>0&&day<=maxDays)) { haserror=true; errormsg+="<li>error! there isn't "+day+ "days in this month!</li>"; } if(haserror) {out.print("your input is "+year+"-"+month+"-"+day+"!"); out.print("<br>"); out.print(errormsg); }else{ out.print("your birthday is "+year+"_"+month+"_"+day+"!"); } %> </body> </html>
int year=my_int.parseInt(stryear);
int month=my_int.parseInt(strmonth);
int day=my_int.parseInt(strday);
改成
int year = Integer.parseInt(stryear);
int month = Integer.parseInt(strmonth);
int day = Integer.parseInt(strday);
<head>
<title>test</title>
</head>
<body>
<%
String stryear=request.getParameter("year");
String strmonth=request.getParameter("month");
String strday=request.getParameter("day");
Integer my_int=new Integer(0);
if (stryear==null) stryear="2004";
if (strmonth==null) strmonth="4";
if (strday==null) strday="18";
int year=my_int.parseInt(stryear);
int month=my_int.parseInt(strmonth);
int day=my_int.parseInt(strday);
boolean haserror=false;
String errormsg="";
if(year<1800||year>3000)
{ haserror=true;
errormsg=" <li>error! year must be in 1800~2001!</li>";
}
if(month>12||month<1)
{haserror=true;
errormsg+=" <li>error! month must be in 1~12!</li>";
}
int maxDays=31;
if(month==4||month==6||month==9||month==11)
{maxDays=30;
}
else if(month==2)
{if (year%4>0)
{maxDays=28;
}else if(year%100==0&&year%400>0)
{maxDays=28;
}else{
maxDays=29;}
}
if(!(day>0&&day<=maxDays))
{
haserror=true;
errormsg+="<li>error! there isn't "+day+ "days in this month!</li>";
}
if(haserror)
{out.print("your input is "+year+"-"+month+"-"+day+"!");
out.print("<br>");
out.print(errormsg);
}else{
out.print("your birthday is "+year+"_"+month+"_"+day+"!");
}
%>
</body>
</html>
your birthday is 2004_4_18!