java myeclipse tomcat struts1

李诗语 发布于 2012/05/20 10:30
阅读 221
收藏 0

严重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
 at org.apache.jsp.index_jsp._jspService(index_jsp.java:142)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
 at java.lang.Thread.run(Unknown Source)

咋么解决呢?纠结了三月了,帮帮忙吧:一下是index.jsp的代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="animal.*" %>

<% Init ini=new Init();
   ini.Initial();
   Fact[] factlist=ini.getFactlist();
   Rule[] rulelist=ini.getRulelist();
   session.setAttribute("factlist",factlist);
   session.setAttribute("rulelist",rulelist);
   session.setAttribute("ini",ini);
%>

 

<!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=UTF-8">
<title>动物识别系统</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 14px}
.navigation{
 font-family: Verdana, sans-serif;
 font-size: 16px;
 font-style: normal;
 font-weight: bold;
 text-decoration: none;
 color: #ffffff;
 background-color: #0066FF;
 display: block;
 padding: 6px;
 width: 100px;
 border-left-color: #FFFFFF;
}
.navigation:hover{
 font-family: Verdana, sans-serif;
 font-size: 16px;
 font-style: normal;
 font-weight: bold;
 text-decoration: none;
 color: #CCCC00;
 background-color: #3399FF;
 display: block;
 padding: 6px;
 width: 100px;
 border-left-color: #FFFFFF;
}
body {
 background-image: url(images/back.JPG);
}
</style>
</head>
<body>

 


  <div align="center">
    <table width="1049" border="0">
      <tr>
        <td width="196"><img src="images/logo.jpg" width="196" height="122"></td>
        <td width="843"><img src="images/pic.JPG" width="843" height="122"></td>
      </tr>
      <tr>
        <td colspan="2"><table width="1045" border="0">
          <tr>
            <td width="230" height="32">&nbsp;</td>
            <td width="100" > <a href="index.jsp"><span class="navigation">&nbsp;推理首页</span></a></td>
            <td width="100" ><a href="newrule.jsp"><span class="navigation">&nbsp;增加规则</span></a></td>
            <td width="100" ><a href="deleterule.jsp"><span class="navigation">&nbsp;删除规则</span></a></td>
            <td width="100" ><a href="rule.jsp"><span class="navigation">&nbsp;所有规则</span></a></td>
            <td width="100" ><a href="rule2.jsp"><span class="navigation">&nbsp;恢复默认</span></a></td>
            <td width="190">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td colspan="2"><table width="1045" border="0">
          <tr>
            <td width="489">&nbsp;</td>
            <td width="376"><table width="376" border="0">
              <tr>
                <div align="center">
                  <td width="370"><form name="form1" method="post" action="illation.do">
                      <div align="left">
                        <% for(int i=0;i<factlist.length;i++)
                        {
          if(factlist[i].getIsfinal()==1)
           continue; %>
           </div>
                      <div>
                      </div>
                    <label>
                      <div align="left">
                        <input type="checkbox" name=<%=new String("fact"+factlist[i].getIndex()) %> value="<%=factlist[i].getIndex()%>">
                        <span class="STYLE1"><%=factlist[i].getName()%></span></div>
                    </label>
                      <div align="left">
                        <% }%>
                        <label>
                        <input name="Submit" type="submit" class="STYLE1" value="推理">
                        </label>
                      </div>
                  </form>
                  <div></div>
            </table></td>
            <td width="166">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
    </table>
  </div>
</body>
</html>

加载中
0
nubo
nubo
NullPointerException空指针异常: index_jsp.java:142
0
李诗语
嗯,我知道,但是咋么改呢?
0
李诗语
<% for(int i=0;i<factlist.length;i++)
                        {
          if(factlist[i].getIsfinal()==1)
           continue; %>
是这段代码吧,但是我觉得没问题呀,麻烦您看看吧
0
vitou
vitou

是不是 你的factlist 为空?

 

0
李诗语

不是呀,我的factlist是用类Init初始化过的,您给帮我看看吧,下面是Init类的代码:

package animal;

 

import java.sql.*;

public class Init {

private Fact[] factlist;

private Rule[] rulelist;

public Fact[] getFactlist() {

return factlist;

}

public void setFactlist(Fact[] factlist) {

this.factlist = factlist;

}

public Rule[] getRulelist() {

return rulelist;

}

public void setRulelist(Rule[] rulelist) {

this.rulelist = rulelist;

}

public void Initial(){

try{

Class.forName("org.gjt.mm.mysql.Driver");

Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/animal","root","lishiyu");    

Statement stmt=conn.createStatement();

//根据Fact总数创建fact数组

String sql = "select count(*) from fact";

   ResultSet rs=stmt.executeQuery( sql );

   rs.next();

   factlist=new Fact[rs.getInt(1)];

   

   //根据Rule总数创建rule数组

   sql = "SELECT count(distinct rule_condition.rindex) FROM rule_condition";

   rs=stmt.executeQuery( sql );

   rs.next();

   rulelist=new Rule[rs.getInt(1)];

   

  

   //读入所有条件的基本信息

   sql = "select * from fact";

   rs=stmt.executeQuery( sql );

   while( rs.next() ){ 

    Fact temp=new Fact(rs.getInt(1),rs.getString(2),rs.getInt(3),0);

    factlist[rs.getInt(1)-1]=temp;

   }

   

   //确定每个条件在所有规则出现次数

   sql = "SELECT rule_condition.rcondition,count(rule_condition.rindex) FROM rule_condition group by rule_condition.rcondition";

   rs=stmt.executeQuery( sql );

   while( rs.next() ){ 

    factlist[rs.getInt(1)-1].rulelist=new Rule[rs.getInt(2)];

   }

   sql = "SELECT rule_conclusion.rconclusion,count(rule_conclusion.rindex) FROM rule_conclusion group by rule_conclusion.rconclusion";

   rs=stmt.executeQuery( sql );

   while( rs.next() ){ 

    factlist[rs.getInt(1)-1].rulelisttail=new Rule[rs.getInt(2)];

   }

   

   //建立规则数组

   for(int i=0;i<rulelist.length;i++){

    rulelist[i]=new Rule(i+1,0);

   }

   

   //确定每条规则的条件数

   sql = "SELECT rule_condition.rindex,count(rule_condition.rcondition) FROM rule_condition group by rule_condition.rindex";

   rs=stmt.executeQuery( sql );

   while( rs.next() ){ 

    rulelist[rs.getInt(1)-1].condlist=new Fact[rs.getInt(2)];

   }

   

   //完成相关引用数组的完善

   sql = "select * from rule_condition";

   rs=stmt.executeQuery( sql );

   while( rs.next() ){ 

    rulelist[rs.getInt(1)-1].addCondition(factlist[rs.getInt(2)-1]);

    factlist[rs.getInt(2)-1].addRule(rulelist[rs.getInt(1)-1]);

   }

   

   sql = "select * from rule_conclusion";

   rs=stmt.executeQuery( sql );

   while( rs.next() ){ 

    rulelist[rs.getInt(1)-1].result=factlist[rs.getInt(2)-1];

    factlist[rs.getInt(2)-1].addRuleTail(rulelist[rs.getInt(1)-1]);

   }

}catch(Exception e){} 

}

public void Back(){

try{

Class.forName("org.gjt.mm.mysql.Driver");

Connection conn=DriverManager.getConnection("jdbc:mysql://localhost/animal","root","lishiyu");    

Statement stmt=conn.createStatement();

stmt.executeUpdate("delete from fact");

stmt.executeUpdate("delete from rule_condition");

stmt.executeUpdate("delete from rule_conclusion");

 

stmt.executeUpdate("insert into fact values(1,'有毛发',0)");

stmt.executeUpdate("insert into fact values(2,'有奶',0)");

stmt.executeUpdate("insert into fact values(3,'有羽毛',0)");

stmt.executeUpdate("insert into fact values(4,'会飞',0)");

stmt.executeUpdate("insert into fact values(5,'会下蛋',0)");

stmt.executeUpdate("insert into fact values(6,'吃肉',0)");

stmt.executeUpdate("insert into fact values(7,'有犬齿',0)");

stmt.executeUpdate("insert into fact values(8,'有爪',0)");

stmt.executeUpdate("insert into fact values(9,'眼盯前方',0)");

stmt.executeUpdate("insert into fact values(10,'是哺乳动物',0)");

stmt.executeUpdate("insert into fact values(11,'有蹄',0)");

stmt.executeUpdate("insert into fact values(12,'是嚼反刍动物',0)");

stmt.executeUpdate("insert into fact values(13,'是肉食动物',0)");

stmt.executeUpdate("insert into fact values(14,'是黄褐色',0)");

stmt.executeUpdate("insert into fact values(15,'身上有黑色条纹',0)");

stmt.executeUpdate("insert into fact values(16,'是有蹄类动物',0)");

stmt.executeUpdate("insert into fact values(17,'有长脖子',0)");

stmt.executeUpdate("insert into fact values(18,'有长腿',0)");

stmt.executeUpdate("insert into fact values(19,'身上有暗斑点',0)");

stmt.executeUpdate("insert into fact values(20,'是鸟',0)");

stmt.executeUpdate("insert into fact values(21,'不会飞',0)");

stmt.executeUpdate("insert into fact values(22,'会游泳',0)");

stmt.executeUpdate("insert into fact values(23,'有黑白二色',0)");

stmt.executeUpdate("insert into fact values(24,'善飞',0)");

stmt.executeUpdate("insert into fact values(25,'是金钱豹',1)");

stmt.executeUpdate("insert into fact values(26,'是虎',1)");

stmt.executeUpdate("insert into fact values(27,'是长颈鹿',1)");

stmt.executeUpdate("insert into fact values(28,'是斑马',1)");

stmt.executeUpdate("insert into fact values(29,'是鸵鸟',1)");

stmt.executeUpdate("insert into fact values(30,'是企鹅',1)");

stmt.executeUpdate("insert into fact values(31,'是信天翁',1)");

stmt.executeUpdate("insert into rule_condition values(1,1)");

stmt.executeUpdate("insert into rule_condition values(2,2)");

stmt.executeUpdate("insert into rule_condition values(3,3)");

stmt.executeUpdate("insert into rule_condition values(4,4)");

stmt.executeUpdate("insert into rule_condition values(4,5)");

stmt.executeUpdate("insert into rule_condition values(5,6)");

stmt.executeUpdate("insert into rule_condition values(6,7)");

stmt.executeUpdate("insert into rule_condition values(6,8)");

stmt.executeUpdate("insert into rule_condition values(6,9)");

stmt.executeUpdate("insert into rule_condition values(7,10)");

stmt.executeUpdate("insert into rule_condition values(7,11)");

stmt.executeUpdate("insert into rule_condition values(8,10)");

stmt.executeUpdate("insert into rule_condition values(8,12)");

stmt.executeUpdate("insert into rule_condition values(9,10)");

stmt.executeUpdate("insert into rule_condition values(9,13)");

stmt.executeUpdate("insert into rule_condition values(9,14)");

stmt.executeUpdate("insert into rule_condition values(9,19)");

stmt.executeUpdate("insert into rule_condition values(10,10)");

stmt.executeUpdate("insert into rule_condition values(10,13)");

stmt.executeUpdate("insert into rule_condition values(10,14)");

stmt.executeUpdate("insert into rule_condition values(10,15)");

stmt.executeUpdate("insert into rule_condition values(11,16)");

stmt.executeUpdate("insert into rule_condition values(11,17)");

stmt.executeUpdate("insert into rule_condition values(11,18)");

stmt.executeUpdate("insert into rule_condition values(11,19)");

stmt.executeUpdate("insert into rule_condition values(12,16)");

stmt.executeUpdate("insert into rule_condition values(12,15)");

stmt.executeUpdate("insert into rule_condition values(13,20)");

stmt.executeUpdate("insert into rule_condition values(13,17)");

stmt.executeUpdate("insert into rule_condition values(13,18)");

stmt.executeUpdate("insert into rule_condition values(13,21)");

stmt.executeUpdate("insert into rule_condition values(14,20)");

stmt.executeUpdate("insert into rule_condition values(14,22)");

stmt.executeUpdate("insert into rule_condition values(14,21)");

stmt.executeUpdate("insert into rule_condition values(14,23)");

stmt.executeUpdate("insert into rule_condition values(15,20)");

stmt.executeUpdate("insert into rule_condition values(15,24)");

 

stmt.executeUpdate("insert into rule_conclusion values(1,10)");

stmt.executeUpdate("insert into rule_conclusion values(2,10)");

stmt.executeUpdate("insert into rule_conclusion values(3,20)");

stmt.executeUpdate("insert into rule_conclusion values(4,20)");

stmt.executeUpdate("insert into rule_conclusion values(5,13)");

stmt.executeUpdate("insert into rule_conclusion values(6,13)");

stmt.executeUpdate("insert into rule_conclusion values(7,16)");

stmt.executeUpdate("insert into rule_conclusion values(8,16)");

stmt.executeUpdate("insert into rule_conclusion values(9,25)");

stmt.executeUpdate("insert into rule_conclusion values(10,26)");

stmt.executeUpdate("insert into rule_conclusion values(11,27)");

stmt.executeUpdate("insert into rule_conclusion values(12,28)");

stmt.executeUpdate("insert into rule_conclusion values(13,29)");

stmt.executeUpdate("insert into rule_conclusion values(14,30)");

stmt.executeUpdate("insert into rule_conclusion values(15,31)");

 

 

}catch(Exception e){} 

}

}

0
李诗语
数据库也是好的,连接过了
返回顶部
顶部