Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HTTP状态500-在第104行处理JSP页面/header.JSP时发生异常_Java_Jsp_Connection - Fatal编程技术网

Java HTTP状态500-在第104行处理JSP页面/header.JSP时发生异常

Java HTTP状态500-在第104行处理JSP页面/header.JSP时发生异常,java,jsp,connection,Java,Jsp,Connection,我得到以下错误: org.apache.jasper.jaspereException:处理时发生异常 第104行的JSP page/header.JSP 根本原因 java.lang.NullPointerException org.apache.jsp.header_jsp._jspService(header_jsp.java:235) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.serv

我得到以下错误:

org.apache.jasper.jaspereException:处理时发生异常 第104行的JSP page/header.JSP

根本原因

java.lang.NullPointerException
org.apache.jsp.header_jsp._jspService(header_jsp.java:235)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
这是我的分类

  public ArrayList<Category> getListCategory() throws SQLException, ClassNotFoundException {
    Connection cons = DBconnect.getConnecttion();
    String sql = "SELECT * FROM category";
    ArrayList<Category> list = new ArrayList<>();
    PreparedStatement ps = null;//cai
    try {
        try {
            ps = (PreparedStatement) cons.prepareStatement(sql);
        } catch (Exception e) {

            return null;
        }
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            Category category = new Category();
            category.setCategoryID(rs.getLong("category_id"));
            category.setCategoryName(rs.getString("category_name"));
            list.add(category);
        }
        cons.close();
    } catch (SQLException e) {
         cons.close();
        return null;

    }
    return list;
}
我在CategoryDAO中检查了getListCategory(),它仍然有效。 我的代码怎么了?请帮帮我。谢谢大家。

if(categoryDAO.getListCategory()!=null){
if (categoryDAO.getListCategory() != null) {
          for (Category ds : categoryDAO.getListCategory()) {
  out.write("\n");
  out.write("<li><a href=\"products.jsp?category=");
  out.print(ds.getCategoryID());
  out.write(" \"> ");
  out.print(ds.getCategoryName());
  out.write("</a></li>\n");
  out.write("\n");
  out.write("                                    ");
对于(类别ds:categoryDAO.getListCategory()){ 输出。写入(“\n”); out.写出(“
  • \n”); 输出。写入(“\n”); 请写出(“”);
    第235行是:for(类别ds:categoryDAO.getListCategory())
    有什么问题吗?Ramanlfc。

    根本原因表明错误出现在第
    235行
    not
    104
    ,发布jspDo not pick and choose bit of the stack trace to show---在一个代码块中显示整个堆栈跟踪,完成所有CausedBy部分。另外,不要以任何方式修改堆栈跟踪。将其从日志复制/粘贴到问题。对不起,吉姆,这是我第一次发帖。下面第235行,Ramanlfc
      public ArrayList<Category> getListCategory() throws SQLException, ClassNotFoundException {
        Connection cons = DBconnect.getConnecttion();
        String sql = "SELECT * FROM category";
        ArrayList<Category> list = new ArrayList<>();
        PreparedStatement ps = null;//cai
        try {
            try {
                ps = (PreparedStatement) cons.prepareStatement(sql);
            } catch (Exception e) {
    
                return null;
            }
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {
                Category category = new Category();
                category.setCategoryID(rs.getLong("category_id"));
                category.setCategoryName(rs.getString("category_name"));
                list.add(category);
            }
            cons.close();
        } catch (SQLException e) {
             cons.close();
            return null;
    
        }
        return list;
    }
    
     static final String DBNAME = "shop";
    static final String USERNAME = "root";
    static final String PASSWORD = "vancao";
    private static ResultSet rs = null;
    private static Connection connection = null;
    
    public static Connection getConnecttion() throws ClassNotFoundException, SQLException {
        if (connection != null) {
            return connection;
        } else {
            Class.forName("com.mysql.jdbc.Driver");
            String connectionURL = "jdbc:mysql://" + HOSTNAME + ":3306/" + DBNAME + "?useUnicode=true&characterEncoding=UTF-8&useSSL=false";
            connection = DriverManager.getConnection(connectionURL, USERNAME,
                    PASSWORD);
            return connection;
        }
    }
    
    if (categoryDAO.getListCategory() != null) {
              for (Category ds : categoryDAO.getListCategory()) {
      out.write("\n");
      out.write("<li><a href=\"products.jsp?category=");
      out.print(ds.getCategoryID());
      out.write(" \"> ");
      out.print(ds.getCategoryName());
      out.write("</a></li>\n");
      out.write("\n");
      out.write("                                    ");