接手别人的JavaEE项目之前运行正确,添加访问数据库后报tomcat异常

我重装了tomcat,重新导入了项目又再将我修改的添加进去,运行时报tomcat异常,所以应当不是环境问题

报错截图:图片说明

访问数据库按照MVC形式,数据显示在getData.jsp中,servlet为GetDServlet.java,
实现从数据库中取数据的类为getD.java,数据表对应的类为inemo_bean,

下面贴代码:

package Servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
//import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Bean.inemo_bean;

/**

  • Servlet implementation class GetDataServlet
    */
    @WebServlet("/GetDataServlet")
    public class GetDServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**

    • @see HttpServlet#HttpServlet() */ public GetDServlet() { super(); }

    /**

    • @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
    • response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().append("Served at: ").append(request.getContextPath()); GetD gd = new GetD(); ArrayList al = gd.getArrayList(); request.setAttribute("al", al); System.out.println("GetDataServlet.doGet()"); }

    /**

    • @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
    • response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); System.out.println("GetDataServlet.doPost()"); }

}

package Servlet;

import java.sql.SQLException;
import java.util.ArrayList;

import com.Bean.inemo_bean;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;
import com.scut.older.db.DB;

/**

  • Servlet implementation class getData
  • */
    public class GetD {

    private Statement st = null;
    private ResultSet rs = null;
    private Connection ct = null;

    public ArrayList getArrayList() {

    ArrayList<inemo_bean> al = new ArrayList<inemo_bean>();
    String sql = "select * from sensor_data_inemo";
    ct = (Connection) new DB().getConn();
    st = (Statement) new DB().getStatement(ct);
    rs = (ResultSet) new DB().getResultSet(st, sql);
    
    try {
        while (rs.next()) {
            inemo_bean ib = new inemo_bean();
            ib.setId_sensor_data_iNEMO(rs.getInt("id_sensor_data_iNEMO"));
            ib.setDatetime(rs.getInt("datetime"));
            ib.setAccx(rs.getInt("accx"));
            ib.setAccy(rs.getInt("accy"));
            ib.setAccz(rs.getInt("accz"));
            ib.setGyrox(rs.getInt("gyrox"));
            ib.setGyroy(rs.getInt("gyroy"));
            ib.setGyroz(rs.getInt("gyroz"));
            ib.setMagx(rs.getInt("magx"));
            ib.setMagy(rs.getInt("magy"));
            ib.setMagz(rs.getInt("magz"));
            ib.setPress(rs.getInt("press"));
            ib.setTemp(rs.getInt("press"));
            ib.setAltitude(rs.getInt("altitude"));
            ib.setLongitude(rs.getInt("longitude"));
            ib.setLatitude(rs.getInt("latitude"));
    
            al.add(ib);
        }
    } catch (SQLException e) {
        e.printStackTrace();
        System.out.println("getData.getArrayList()");
        System.err.println("getdata()出错");
    } finally {
        closeSource();
    }
    return al;
    

    }

    private void closeSource() {
    try {
    if (rs != null)
    rs.close();
    if (st != null)
    st.close();
    if (ct != null)
    ct.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    public GetD() {
    super();
    }

}

<%@page import="com.Bean.inemo_bean"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



Data from inemo


Get Data From DataBase -sensor_inemo_data





<%
ArrayList al = (ArrayList)request.getAttribute("al");
%>



















<%
for (int i = 1; i <= al.size(); i++) {
inemo_bean inemo = al.get(i);
%>
















    </tr>
    <%
        }
    %>
</table>


id_sensor_data_iNEMO datetime accx accy accz gyrox gyroy gyroz magx magy magz press temp altitude longitude latitude
<%=inemo.getId_sensor_data_iNEMO()%> <%=inemo.getDatetime()%> <%=inemo.getAccx()%> <%=inemo.getAccy()%> <%=inemo.getAccz()%> <%=inemo.getGyrox()%> <%=inemo.getGyroy()%> <%=inemo.getGyroz()%> <%=inemo.getMagx()%> <%=inemo.getMagy()%> <%=inemo.getMagz()%> <%=inemo.getPress()%> <%=inemo.getTemp()%> <%=inemo.getAltitude()%> <%=inemo.getLongitude()%> <%=inemo.getLatitude()%>
ava

6个回答

谢谢大家我自己找到bug了,我的两个servlet在配置文件中写重复了

自己打个断点,F6单步执行。找到报错的地方

是不是tomcat中配置jndi时没配置正确

tomcat里面的catalina里面清除下。

仔细看看配置有没有错误!!

谢谢大家我自己找到bug了,我的两个servlet在配置文件中写重复了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问