<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="view.*" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%!//处理字符串的方法 public String getString(String s) {if(s=="null"){s="";} try{byte b[]=s.getBytes("ISO-8859-1");s=new String(b,"utf-8");} catch(Exception e){} return s; } %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>学生的信息及成绩</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% String Xueyuan=request.getParameter("Xueyuan"); Xueyuan=getString(Xueyuan); String Zhuanye=request.getParameter("Zhuanye"); Zhuanye=getString(Zhuanye); String Xuesheng=request.getParameter("Xuesheng"); Xuesheng=getString(Xuesheng); %> <%if(Xueyuan==null||Zhuanye==null||Xuesheng==null){ %> <%response.sendRedirect("grades3.jsp");//response重定向,引到另一个页面。 %> <%}%> <%String []grades=DB.selectScoreOfName(Xueyuan, Zhuanye, Xuesheng); %> <TABLE border="2" align="center"><%=Xuesheng %>的成绩如下:<br> <TR><TH>学院</TH><TH>专业</TH><TH>学生</TH><TH>语文</TH><TH>数学</TH><TH>外语</TH><TH>平均分</TH></TR> <TR><td><%=Xueyuan %></td><td><%=Zhuanye %></td><td><%=Xuesheng %></td> <%for(int i=0;i<grades.length;i++){%> <td><%=grades[i] %></td> <% } %> </TR> </TABLE> </body> <ml>
<%if(Xueyuan==null||Zhuanye==null||Xuesheng==null){ %>
<%response.sendRedirect("grades3.jsp");//response重定向,引到另一个页面。 %>
<%}%>不应该用==null改用.isEmpty方法。如下:
<%if(Xueyuan.isEmpty()||Zhuanye.isEmpty()||Xuesheng.isEmpty()){ %>
<%response.sendRedirect("grades3.jsp");//response重定向,引到另一个页面。 %>
<%}%>