关于#java#的问题:从数据库读取数据是发生错误信息

从数据库读取数据是发生错误信息,有点错误,一直服务器发生的错误信息,行处理 [/index.jsp] 时发生异常

img

那你后台Java的代码异常需要贴出来,以及你的代码也需要贴出来,不然很难定位到


<%@ page import="java.util.List" %>
<%@ page import="com.NewsProject.model.TbNews" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<title>欢迎访问喜迎二十大,庆建团百年网站</title>
<%@include file="../userpublic/indexIncludeFile.jsp"%>
</head>
<body>
    <jsp:include page="../userpublic/indexMenu.jsp"></jsp:include>
    <div class="contentDiv" >
        <div class="Section_Content_Left" id="contentDiv">
            <div class="Section_Left_Title">政声</div>
            <div class="Section_Left_NewsList">
                <ul>
                    <%
                        List<TbNews> listNews=(List<TbNews>) request.getAttribute("listNews");
                        for (TbNews tbNews: listNews){
                            if(tbNews.getFtypeid()==1){
                                %>
                    <li><a    href="${pageContext.request.contextPath}/Content_News?id=<%=tbNews.getId()%>"    target="_blank">
                        <span class="Section_Left_NewsList_Title"><%=tbNews.getTitle()%></span>
                        <span class="Section_Left_NewsList_Time"><%=tbNews.getInsertTime("yyyy-MM-dd")%></span>
                    </a></li>
                    <%
                    }
                    }
                    %>
                </ul>
            </div>
            <div class="Section_Left_Title">学习要闻</div>
            <div class="Section_Left_NewsList">
                <ul>
                    <%
                        for (TbNews tbNews:listNews){
                            if(tbNews.getFtypeid()==2){
                                %>
                    <li><a    href="${pageContext.request.contextPath}/Content_News?id=<%=tbNews.getId()%>"    target="_blank">
                        <span class="Section_Left_NewsList_Title"><%=tbNews.getTitle()%></span>
                        <span class="Section_Left_NewsList_Time"><%=tbNews.getInsertTime("yyyy-MM-dd")%></span>
                    </a></li>
                    <%
                    }
                    }
                    %>
                </ul>
            </div>
            <div class="Section_Left_Title">大会内容</div>
            <div class="Section_Left_NewsList">
                <ul>
                    <%
                        for (TbNews tbNews:listNews){
                            if(tbNews.getFtypeid()==3){
                    %>
                    <li><a    href="${pageContext.request.contextPath}/Content_News?id=<%=tbNews.getId()%>"    target="_blank">
                        <span class="Section_Left_NewsList_Title"><%=tbNews.getTitle()%></span>
                        <span class="Section_Left_NewsList_Time"><%=tbNews.getInsertTime("yyyy-MM-dd")%></span>
                    </a></li>
                    <%
                            }
                        }
                    %>
                </ul>
            </div>
        </div>
        <div class="Section_Content_Right">
            <jsp:include page="../userpublic/indexRightMenu.jsp"></jsp:include>
        </div>
    <jsp:include page="../userpublic/indexFooter.jsp"></jsp:include>
</body>
</html>



package com.NewsProject.controller;

import com.NewsProject.dao.DBUtils;
import com.NewsProject.model.TbNews;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "Index_News", value = "/Index_News")
public class Index_News extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sql="(select * from tb_news where ftypeid=1 order by id desc limit 5) union(select * from tb_news where ftypeid=2 order by id desc limit 5) union(select * from tb_news where ftypeid=3 order by id desc limit 5)";
        DBUtils dbUtils=new DBUtils();
        List<TbNews> list=(List<TbNews>) dbUtils.executeQueryBeans(sql,TbNews.class);
        request.setAttribute("listNews",list);
        request.getRequestDispatcher("home/Index.jsp").forward(request,response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
    }
}

package com.NewsProject.model;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;

public class TbNews {
    int id;
    String title;
    String content;
    String writer;
    String phoUrl;
    int ftypeid;
    Timestamp insertTime;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    public String getWriter() {
        return writer;
    }
    public void setWriter(String writer) {
        this.writer = writer;
    }
    public String getPhoUrl() {
        return phoUrl;
    }
    public void setPhoUrl(String phoUrl) {
        this.phoUrl = phoUrl;
    }
    public int getFtypeid() {
        return ftypeid;
    }
    public void setFtypeid(int ftypeid) {
        this.ftypeid = ftypeid;
    }
    public String getInsertTime(String fm) {
        if(this.insertTime!=null) {
            SimpleDateFormat df = new SimpleDateFormat(fm);
            return df.format(this.insertTime);
        }
        return "";
    }
    public void setInsertTime(Timestamp insertTime) {
        this.insertTime = insertTime;
    }
}