在一个jsp中显示多个mysql表

时间:2016-02-10 06:06:02

标签: java mysql jsp servlets

尝试设计一个小仪表板 - 我在2个mysql表中准备好了数据。我甚至有DAO和控制器工作正常。我试图在一个jsp上显示这些表...我的doGet()看起来像这样 -

 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String forward = "";
    String action = request.getParameter("action");


        forward = LIST_CASEDETAIL;
        request.setAttribute("casedetails", dao.getDailyBoard());
        request.setAttribute("caseweekly", dao.getWeeklyBoard());

    RequestDispatcher view = request.getRequestDispatcher(forward);
    view.forward(request, response);
}

问题1 - 这是允许的吗? 问题2 - 如果是 - 它不起作用。我的jsp正在DailyBoard上展示。我需要了解我在这里做错了什么。非常感谢您提供所有帮助。以下是来自Controller,DAO&的代码。 JSP

控制器

package com.cts.controller;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



import com.cts.dao.CaseMasterDAO;
import com.cts.dao.ClientDAO;
import com.cts.model.CaseMaster;
import com.cts.model.CaseDetail;
import com.cts.dao.CaseDairyDAO;
import com.cts.model.Client;

public class DashBoardController extends HttpServlet {

private static final long serialVersionUID = 1L;
 //private static String INSERT_OR_EDIT = "/ctsCaseDetailRegistration.jsp";
 private static String LIST_CASEDETAIL = "/DailyBoard.jsp";
 private CaseDairyDAO dao; 
 private ClientDAO clientDAO;

  public DashBoardController() {
    super();
    dao = new CaseDairyDAO();
    clientDAO = new ClientDAO();
}

  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String forward = "";
    String action = request.getParameter("action");


        forward = LIST_CASEDETAIL;
        request.setAttribute("casedetails", dao.getDailyBoard());
        request.setAttribute("caseweekly", dao.getWeeklyBoard());

    RequestDispatcher view = request.getRequestDispatcher(forward);
    view.forward(request, response);
  }
}

DAO

package com.cts.dao;


import java.sql.*;
import java.util.*;
import com.cts.model.CaseDetail;
import com.cts.model.CaseDetail;
import com.cts.model.Client;
import com.cts.util.Database;

public class CaseDairyDAO {
private Connection connection;

public CaseDairyDAO() {
    connection = Database.getConnection();
}

public List<CaseDetail> getDailyBoard() {
    List<CaseDetail> casedetails = new ArrayList<CaseDetail>();
    try {
        Statement statement = connection.createStatement();
        ResultSet rs = statement.executeQuery("SELECT ccd_id,cad_id,cad_RegNo,cad_CaseNo,cad_FileNo,cad_FileName,ccd_CurrentDate,ccd_NextDate,ccd_Stage,ccd_Judge,ccd_Rojnama,ccd_Judgment,ccd_Remarks,ccd_Court,ccd_CreateDate,ccd_CreateUser,ccd_ModifyDate,ccd_ModifyUser,ccd_ActiveFlag,ccd_DeleteFlag  FROM cts_casediarydetails Where ccd_CurrentDate = date_format(curdate(), '%Y-%d-%m')");
        while (rs.next()) {
            CaseDetail casedetail = new CaseDetail();

            casedetail.setCcd_ID(rs.getInt("ccd_id"));
            casedetail.setCad_ID(rs.getInt("cad_id"));
            casedetail.setCad_RegNo(rs.getInt("cad_RegNo"));               
            casedetail.setCcd_CreateUser(rs.getInt("ccd_CreateUser"));
            casedetail.setCcd_ModifyUser(rs.getInt("ccd_ModifyUser"));                

            casedetail.setCad_CaseNo(rs.getString("cad_CaseNo"));
            casedetail.setCad_CaseNo(rs.getString("cad_FileNo"));
            casedetail.setCad_FileName(rs.getString("cad_FileName"));
            casedetail.setCcd_Stage(rs.getString("ccd_Stage"));
            casedetail.setCcd_Court(rs.getString("ccd_Court"));
            casedetail.setCcd_Judge(rs.getString("ccd_Judge"));
            casedetail.setCcd_Rojnama(rs.getString("ccd_Rojnama"));
            casedetail.setCcd_Judgment(rs.getString("ccd_Judgment"));
            casedetail.setCcd_Remarks(rs.getString("ccd_Remarks"));                                                
            casedetail.setCcd_CurrentDate(rs.getDate("ccd_CurrentDate"));                
            casedetail.setCcd_NextDate(rs.getDate("ccd_NextDate"));
            casedetail.setCcd_CreateDate(rs.getDate("ccd_CreateDate"));
            casedetail.setCcd_ModifyDate(rs.getDate("ccd_ModifyDate"));

            casedetail.setCcd_ActiveFlag(rs.getBoolean("ccd_ActiveFlag"));
            casedetail.setCcd_DeleteFlag(rs.getBoolean("ccd_DeleteFlag"));

            casedetails.add(casedetail);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }

    return casedetails;
}

public List<CaseDetail> getWeeklyBoard() {
    List<CaseDetail> caseweekls = new ArrayList<CaseDetail>();
    try {
        Statement statement = connection.createStatement();
        ResultSet rs = statement.executeQuery("SELECT ccd_id,cad_id,cad_RegNo,cad_CaseNo,cad_FileNo,cad_FileName,ccd_CurrentDate,ccd_NextDate,ccd_Stage,ccd_Judge,ccd_Rojnama,ccd_Judgment,ccd_Remarks,ccd_Court,ccd_CreateDate,ccd_CreateUser,ccd_ModifyDate,ccd_ModifyUser,ccd_ActiveFlag,ccd_DeleteFlag  FROM cts_casediarydetails  Where yearweek(date_format(ccd_CurrentDate,'%Y-%d-%m')) = yearweek(curdate())");
        while (rs.next()) {
            CaseDetail casewdetail = new CaseDetail();

            casewdetail.setCcd_ID(rs.getInt("ccd_id"));
            casewdetail.setCad_ID(rs.getInt("cad_id"));
            casewdetail.setCad_RegNo(rs.getInt("cad_RegNo"));               
            casewdetail.setCcd_CreateUser(rs.getInt("ccd_CreateUser"));
            casewdetail.setCcd_ModifyUser(rs.getInt("ccd_ModifyUser"));                

            casewdetail.setCad_CaseNo(rs.getString("cad_CaseNo"));
            casewdetail.setCad_CaseNo(rs.getString("cad_FileNo"));
            casewdetail.setCad_FileName(rs.getString("cad_FileName"));
            casewdetail.setCcd_Stage(rs.getString("ccd_Stage"));
            casewdetail.setCcd_Court(rs.getString("ccd_Court"));
            casewdetail.setCcd_Judge(rs.getString("ccd_Judge"));
            casewdetail.setCcd_Rojnama(rs.getString("ccd_Rojnama"));
            casewdetail.setCcd_Judgment(rs.getString("ccd_Judgment"));
            casewdetail.setCcd_Remarks(rs.getString("ccd_Remarks"));                                                
            casewdetail.setCcd_CurrentDate(rs.getDate("ccd_CurrentDate"));                
            casewdetail.setCcd_NextDate(rs.getDate("ccd_NextDate"));
            casewdetail.setCcd_CreateDate(rs.getDate("ccd_CreateDate"));
            casewdetail.setCcd_ModifyDate(rs.getDate("ccd_ModifyDate"));

            casewdetail.setCcd_ActiveFlag(rs.getBoolean("ccd_ActiveFlag"));
            casewdetail.setCcd_DeleteFlag(rs.getBoolean("ccd_DeleteFlag"));

            caseweekls.add(casewdetail);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }

    return caseweekls;
  }
}

JSP

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>

    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.10/css/dataTables.jqueryui.min.css">
    <script type="text/javascript" language="javascript" src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.10/js/dataTables.jqueryui.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var table = $('#example').DataTable({
                "sScrollX": "500%",
                "sScrollXInner": "110%",
                "bScrollCollapse": true,
                columnDefs: [{targets: [0, 1, 2, 4, 5], width: "300px"}]
            });
        });
    </script>
    <style>

        panel-body {
            width: 1000px;
            margin: 0 auto;
        }
    </style>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>SB Admin - Bootstrap Admin Template</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/sb-admin.css" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link href="css/plugins/morris.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">


</head>
<body>
    <div id="wrapper">




                        <div class="col-lg-4">
                            <div class="panel panel-default" style="width: 1000px;">
                                <div class="panel-heading" style="width: 1000px;">
                                    <h3 class="panel-title" style="width: 1000px;"><i class="fa fa-money fa-fw"></i>Daily Board</h3>
                                </div>

                                <form role="form">

                                    <table class="table table-bordered table-hover table-striped" id="example" class="display" cellspacing="0" width="100%">
                                        <thead>
                                            <tr>
                                                <th>Register No</th>                                                              
                                                <th>Case Number</th>
                                                <th>File Name</th>
                                                <th>Current Date</th>                    
                                                <th>Next Date</th>
                                                <th>Stage</th>
                                                <th>Judge</th>                    
                                                <th>Rojnama</th>
                                                <th>Judgment</th>
                                                <th>Remarks</th>                    
                                                <th>Court</th>                                             
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <c:forEach items="${casedetails}" var="casedetail">
                                                <tr>
                                                    <td><c:out value="${casedetail.cad_RegNo}" /></td>                                                
                                                    <td><c:out value="${casedetail.cad_CaseNo}" /></td>
                                                    <td><c:out value="${casedetail.cad_FileName}" /></td>
                                                    <td><c:out value="${casedetail.ccd_CurrentDate}" /></td>
                                                    <td><c:out value="${casedetail.ccd_NextDate}" /></td>
                                                    <td><c:out value="${casedetail.ccd_Stage}" /></td>
                                                    <td><c:out value="${casedetail.ccd_Judge}" /></td>
                                                    <td><c:out value="${casedetail.ccd_Rojnama}" /></td>
                                                    <td><c:out value="${casedetail.ccd_Judgment}" /></td>
                                                    <td><c:out value="${casedetail.ccd_Remarks}" /></td>
                                                    <td><c:out value="${casedetail.ccd_Court}" /></td>                                                                                                                                                                                            
                                                </tr>
                                            </c:forEach>
                                        </tbody>
                                    </table>
                                </form>
                            </div>
                            <div class="text-right">
                                <a href="#">View All Cases <i class="fa fa-arrow-circle-right"></i></a>
                            </div>
                        </div>



                    </div>
                    <!-- /.row -->
                    <div class="row">
                        <div class="col-lg-4">
                            <div class="panel panel-default" style="width: 1000px;">
                                <div class="panel-heading" style="width: 1000px;">
                                    <h3 class="panel-title" style="width: 1000px;"><i class="fa fa-money fa-fw"></i>Weekly Board</h3>
                                </div>

                                <form role="form">

                                    <table class="table table-bordered table-hover table-striped" id="example1" class="display" cellspacing="0" width="100%">
                                        <thead>
                                            <tr>
                                                <th>Register No</th>                                                              
                                                <th>Case Number</th>
                                                <th>File Name</th>
                                                <th>Current Date</th>                    
                                                <th>Next Date</th>
                                                <th>Stage</th>
                                                <th>Judge</th>                    
                                                <th>Rojnama</th>
                                                <th>Judgment</th>
                                                <th>Remarks</th>                    
                                                <th>Court</th>                                             
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <c:forEach items="${caseweekls}" var="casewdetail">
                                                <tr>
                                                    <td><c:out value="${casewdetail.cad_RegNo}" /></td>                                                
                                                    <td><c:out value="${casewdetail.cad_CaseNo}" /></td>
                                                    <td><c:out value="${casewdetail.cad_FileName}" /></td>
                                                    <td><c:out value="${casewdetail.ccd_CurrentDate}" /></td>
                                                    <td><c:out value="${casewdetail.ccd_NextDate}" /></td>
                                                    <td><c:out value="${casewdetail.ccd_Stage}" /></td>
                                                    <td><c:out value="${casewdetail.ccd_Judge}" /></td>
                                                    <td><c:out value="${casewdetail.ccd_Rojnama}" /></td>
                                                    <td><c:out value="${casewdetail.ccd_Judgment}" /></td>
                                                    <td><c:out value="${casewdetail.ccd_Remarks}" /></td>
                                                    <td><c:out value="${casewdetail.ccd_Court}" /></td>                                                                                                                                                                                            
                                                </tr>
                                            </c:forEach>
                                        </tbody>
                                    </table>
                                </form>
                            </div>
                            <div class="text-right">
                                <a href="#">View All Cases <i class="fa fa-arrow-circle-right"></i></a>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.container-fluid -->

            </div>


        </div>
        <!-- /.container-fluid -->

    </div>
    <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <!-- Morris Charts JavaScript -->
    <script src="js/plugins/morris/raphael.min.js"></script>
    <script src="js/plugins/morris/morris.min.js"></script>
    <script src="js/plugins/morris/morris-data.js"></script>

</body>
</html>

2 个答案:

答案 0 :(得分:0)

对于JSP中的每周,你输错了名字,它应该是

Time.now

同样在你的DAO中,我认为你将caseNo分配了两次,另一个应该是fileNo,对吗?

答案 1 :(得分:0)

尝试添加页面名称jsp:

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")

    from django.core.management import execute_from_command_line

    load_env()
    execute_from_command_line(sys.argv)

因为前锋需要 String forward = "some_name.jsp";

并尝试替换它:

page jsp

使用:

 <c:forEach items="${caseweekls}" var="casewdetail">