Jsp从多个数据库收集信息

时间:2014-11-13 06:59:31

标签: jsp servlets

我有一些数据库需要连接到Servlet;(这些数据库是假的,适用于学校项目)
首先我需要抓住学生数据库:
到达StudentSchedule
到达章节:
最终获得学生正在学习的课程名称http://puu.sh/cO7gN/9d303ebe8b.png

我目前创建了一个Servlet来收集这些信息:

 @WebServlet(urlPatterns = {"/ScheduleServlet"})
    public class ScheduleServlet extends HttpServlet {


        /**
         * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
         * methods.
         *
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
         */

        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            try (PrintWriter out = response.getWriter()) {
                /* TODO output your page here. You may use following sample code. */

              int iD = Integer.parseInt(request.getParameter("iD"));
               int cRN = Integer.parseInt(request.getParameter("cRN"));
               String courseID = request.getParameter("courseID");
               String courseName = request.getParameter("courseName");
               System.out.println(iD); 

                Student s1=new Student();
                s1.findDB(iD);

                StudentSchedule s2 = new StudentSchedule();
                s2.findDB(cRN);


                Section s3 = new Section();
                s3.findDB(cRN);


                Course s4 = new Course();
                s4.findDB(courseID);
                 s4.findDB(courseName);

                String cn=s4.getCourseName();
                System.out.println(cn);
                RequestDispatcher rd;

                HttpSession ses1=request.getSession();
                ses1.setAttribute("s4", s4);


                    rd = request.getRequestDispatcher("/ScheduleView.jsp");
                    rd.forward(request,response);



            }
        }

        // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
        /**
         * Handles the HTTP <code>GET</code> method.
         *
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
         */
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
        }

        /**
         * Handles the HTTP <code>POST</code> method.
         *
         * @param request servlet request
         * @param response servlet response
         * @throws ServletException if a servlet-specific error occurs
         * @throws IOException if an I/O error occurs
         */
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
        }

        /**
         * Returns a short description of the servlet.
         *
         * @return a String containing servlet description
         */

        @Override
        public String getServletInfo() {
            return "Short description";
        }// </editor-fold>

    }

我还有一个网页可以提取他们的信息:http://puu.sh/cO7p0/5f64c27869.jpg
但是,一旦我点击查看日程按钮,就没有关于&#34;拉里&#34;的信息。课程揭晓。

如何获取解决此问题所需的信息?我做错了什么?


代码是:

 <%@page import="Business.Student"%>
    <%@page import="Business.StudentSchedule"%>
    <%@page import="Business.Section"%>
    <%@page import="Business.Course"%>

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Schedule View</title>
        </head>
        <body>

             <%
                HttpSession ses1=request.getSession();
                Course s4= (Course)ses1.getAttribute("s4");


                %> 

                <h4>Here is your Information</h4>
            <table border="1" width="75%" cellspacing="5" cellpadding="2">
                <thead>
                    <tr>
                        <th colspan="10">Student Info</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                         <%--TABLE LABLES OF ACCOUNT INFORMATION  --%>
                        <td colspan="2"></td>
                        <td colspan="2">Course Name</td>
                    </tr>
                    <tr>
                        <%--TABLE DISPLAY OF ACCOUNT INFORMATION  --%>
                        <td colspan="2">Classes: </td>
                        <td colspan="2"><%= s4.getCourseName()%></td>
                        </tr>



                </tbody>
            </table>
                    <table width="50%" cellspacing="5" cellpadding="2">


            </table>  
        </body>
    </html>

注意:我可以连接到数据库,我只需要找到一种方法让servlet工作,让学生在数据库上查看计划,所有Business Objects都在工作,因为我已经测试过了他们把工作放到jsp页面,从收集所有数据库中获取信息,这就是问题,让JSP页面通过所有数据库来获得实际的学生课程。 我可以连接到数据库,我只是想看看如何使用servlet连接所有以获取我需要的信息来找到这些类。

0 个答案:

没有答案