<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>if嵌套表单</title> </head> <body> <DIV ALIGN="center"> 将学生成绩由百分制转换成5分制<br><br> <form action="if嵌套.jsp"> 请输入成绩:<input type=text name="score"><br><br> <input type=submit value=提交> <input type=reset value=重填> </form> </DIV> </body> </html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!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=ISO-8859-1"> <title>if嵌套</title> </head> <body> <% int score=Integer.parseInt(request.getParameter("score"));//获取表单成绩 if(score==100){ out.print(5); }else if(score>=80&&score<100){ out.print(4); }else if(score>=60&&score<80){ out.print(3); }else if(score>=40&&score<60){ out.print(2); }else if(score>=20&&score<40){ out.print(1); }else if(score>=0&&score<20){ out.print(0); }else{ out.print("分数输入有误"); } %> </body> </html>