为什么这段代码不显示输入框而直接跳转到了错误页面
这是主页面代码
程序代码:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. <title>one</title> <jsp:include page="head.txt" /> </head> <body bgcolor="yellow"> <embed src="f:\1.mp3" /> <form method="post" name="form"> 请输入1到100之间的整数: <input type="text" name="num" value="3"/><br /> <input type="submit" value="提交" name="submit" /> </form> <jsp:include page="judge.jsp" /> </body> </html>
judge.jsp的代码:
程序代码:
<% String number; number=request.getParameter("num"); if(number==null) number="0"; try{ int n=Integer.parseInt(number); if(n==0){ %> <jsp:forward page="one.jsp" /> <% } else if(n>=1 && n<=50){ %> <jsp:forward page="two.jsp"> <jsp:param name="number" value="<%= n%>" /> </jsp:forward> <% } else if(n>50 && n<=100){ %> <jsp:forward page="three.jsp"> <jsp:param name="number" value="<%= n%>" /> </jsp:forward> <% } else{ %> <jsp:forward page="error.jsp"> <jsp:param name="mess" value="1" /> </jsp:forward> <% } }catch(Exception e){ %> <jsp:forward page="error.jsp"> <jsp:param name="mess" value="2" /> </jsp:forward> <% } %>
下面是error.jsp的代码以及运行截图
程序代码:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>error.jsp</title> <jsp:include page="head.txt" /> </head> <body bgcolor="yellow"> <font size="5" color="red">This is error.jsp</font> <font size="2"> <% String s=request.getParameter("mess"); out.println("<br />传递过来的错误信息:"+s); %> </font> </body> </html>