代码呢,你这样我们如何知道啊
 一般比较的话,常量最好在前面
 如
 if("".equals())....

解决方案 »

  1.   

    我的是一个JSP,用途是增加学生,学生的专业是从数据库的specialty表中得出,我用的是Hibernate,我的JSP代码如下:
    <%@ page language="java" contentType="text/html; charset=GBK"%>
    <jsp:directive.page import="com.zel.dao.DAOFactory" />
    <jsp:directive.page import="com.zel.domain.Specialty" />
    <jsp:directive.page import="com.zel.dao.SpecialtyDAO" />
    <jsp:directive.page import="java.util.*" />
    <jsp:directive.page import="java.lang.Exception" />
    <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
    <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
    <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
    <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html:html lang="true">
    <head>
    <html:base /> <title>添加学生界面</title>
    <style type="text/css">
    <!--
    .style1 {
    color: #0000FF;
    font-weight: bold;
    font-size: xx-large;
    }
    .style2 {color: #FF0000}
    -->
        </style> <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 admin_id = (String) session.getAttribute("id");
    if (admin_id == null) {
    response.sendRedirect("login.jsp");
    } --%>
    <%  int total=-1;
        Iterator it =null;
        Specialty spe;
    String spename;
        try{
        SpecialtyDAO speDao = DAOFactory.getInstance().createSpecialtyDAO();
        if(speDao!=null){
    List list = speDao.getSpecialty();
    total = list.size();
    it = list.iterator();
    }else{System.out.println("这里的JAVA代码不能运行!!!");}}catch(Exception e){
    out.print("<br>");
    out.print("抛出的异常信息为:"+e.toString());
    }
    finally{
     //total=1;
    spename="2004数学与应用数学";

    }

    %>
    <h1 class="style1" align="center">
    添加学生
    </h1>
    <html:form method="post" action="/student">
    <center>
    <span class="style2"> <html:errors /> </span>
    </center>
    <table width="49%" height="50" border="0" align="center"
    cellpadding="2" cellspacing="2">
    <tr>
    <td align="right" width="30%">
    学生学号:
    </td>
    <td width="60%" border="4">
    <html:text property="stunumber" value="" />
    <html:errors property="stunumber.null" />
    </td>
    </tr>
    <tr>
    <td align="right" width="30%">
    学生姓名:
    </td>
    <td width="60%" border="4">
    <html:text property="name" value="" />
    <html:errors property="studentname.null" />
    </td>
    </tr>
    <tr>
    <td align="right" width="30%">
    学生密码:
    </td>
    <td width="60%" border="4">
    <html:text property="password" value="" />
    <html:errors property="password.null" />
    </td>
    </tr>
    <%
    if (it != null) {
    %>
    <tr>
    <td align="right">
    学生专业:
    </td>
    <td border="4">
    <html:select property="spe_name" multiple="true" size="3" value="0">
    <%
      for (int i = 0; i < total; i++) {
    spe = (Specialty) it.next();
    spename = spe.getSpename();
    %>
     <html:option key="a<%=i%>" value="<%=spename%>"><%=spename%></html:option>
    <%
    }
    %>
    </html:select>
    <html:errors property="spe_name.null" />
    </td>
    </tr>
    <%
    } else {
    %>
    <center>
    <h4 class="style2" align="center">
    <%="遗憾,专业不能从数据库中得出!"%>
    </h4>
    </center>
    <tr>
    <td align="right">
    学生专业:
    </td>
    <td border="4">
    <html:text property="spe_name" value="<%=spename%>" />
    </td>
    </tr> <%
    }
    %>
    <tr>
    <td></td>
    <td>
    <html:submit value="提交" />
    </td>
    </tr>
    </table>
    </html:form>
    <p align="center">
    &nbsp; </p>
    <a href="admin.jsp">&lt;&lt;返回 </a>
    </body>
    </html:html>
      

  2.   

    你打印以下list变量的值看看。
      

  3.   

     try{ 
        SpecialtyDAO speDao = DAOFactory.getInstance().createSpecialtyDAO(); 
        if(speDao!=null){ 
           List list = speDao.getSpecialty(); 
          total = list.size();  //判断下 list 是不是null就ok了,为空的话检查 SpecialtyDAO的getSpecialty()方法吧
          it = list.iterator(); 
        }else{System.out.println("这里的JAVA代码不能运行!!!");}}catch(Exception e){ 
    out.print(" <br>"); 
    out.print("抛出的异常信息为:"+e.toString());