Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    cax
    cax is offline
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation help needed...jsp beginner

    hello everyone. i need help to solve my jsp problem. and FYI, i'm a beginner to jsp..

    my problem is i cannot view table in viewbook.jsp..

    here is my code for viewbook.jsp
    Code:
    <%@ page import="mvc.ProfileBean" %>
    <%@ page import="java.util.Vector" %>
    <%@ page import="java.lang.Integer" %>
    <%@ page import="mvc.BookRequestBean" %>
    <%
                ProfileBean pb = (ProfileBean) session.getAttribute("ProfileBean");
    
                if (pb == null) {
    %>
    <jsp:forward page="terminate.html" />
    <%            }
    
                //String status = request.getParameter("status");
                Vector crbv = (Vector) session.getAttribute("BookRequestBeanVector");
    %>
    <html>
    <body>
    <table width="400" border="1">
    <tr>
          <td>Index</td>
          <td>Halls</td>
           <td>Event</td>
            <td>Date & Time</td>
           <td>People Attending</td>
           <td>Status</td>
    </tr>
    <%
     for (int i = 0; i < crbv.size(); i++) 
    {
        BookRequestBean crb = (BookRequestBean) crbv.elementAt(i);
        int index = i + 1;
     %>
          <tr>
                <td><%= index%></td>
                <td><%= crb.getHalls()%></td>
                 <td><%= crb.getEvent()%></td>
                  <td><%= crb.getDateTime1()%> to <%= crb.getDateTime2()%></td>
                  <td><%= crb.getAttend()%></td>
                  <td><%= crb.getStatus()%></td>
                   </tr>
    <%
            }
    %>
    </table>
    and here is my servlet
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package mvc;
    
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    
    import javax.servlet.*;
    import javax.servlet.http.*;
    
    public class ViewBookingServlet extends HttpServlet {
    
        private JdbcUtility jdbcUtility;
        private Connection con;
        private ConnectionPool mvcConnectionPool;
    
        public void init() throws ServletException {
            // load ConnectionPool from the Servlet Context
            mvcConnectionPool = (ConnectionPool) getServletContext().getAttribute("MVCConnectionPool");
    
    
            if (mvcConnectionPool == null) {
                //initialized connectionPool class
                String driver = "com.mysql.jdbc.Driver";
                String url = "jdbc:mysql://localhost/mvc?";
                String userName = "root";
                String password = "";
    
                try {
                    mvcConnectionPool = new ConnectionPool(driver,
                            url,
                            userName,
                            password,
                            10, //initial coonection
                            50, //maximum connection
                            true); //wait if busy
    
                    getServletContext().setAttribute("MVCConnectionPool", mvcConnectionPool);
                } catch (Exception ex) {
                }
            }
    
            // jdbcUtility from the Servlet Context
            jdbcUtility = (JdbcUtility) getServletContext().getAttribute("JdbcUtility");
            if (jdbcUtility == null) {
                jdbcUtility = new JdbcUtility();
                getServletContext().setAttribute("JdbcUtility", jdbcUtility);
            }
        }
    
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            HttpSession session = request.getSession(true);
            ProfileBean pb = (ProfileBean) session.getAttribute("ProfileBean");
            String login = pb.getLogin();
    
            String getBookQuery = "SELECT halls, event, date_time1, date_time2, attend, status FROM booking"
                    + "WHERE login = '" + login + "'";
    
            //get database connection from the connection pool
            try {
                con = mvcConnectionPool.getConnection();
            } catch (Exception ex) {
            }
    
            Vector bookRequest = jdbcUtility.jdbcQuery(getBookQuery, con);
    
            //free the connection
            mvcConnectionPool.free(con);
            Vector crv = new Vector<Vector>();
    
            if (bookRequest.size() > 0) {
    
                for (int i = 0; i < bookRequest.size(); i++) {
                    Vector vec = (Vector) bookRequest.elementAt(i);
    
                    BookRequestBean crb = new BookRequestBean();
    
                    String halls = (String) vec.elementAt(0);
                    String event = (String) vec.elementAt(1);
                    String date_time1 = (String) vec.elementAt(2);
                    String date_time2 = (String) vec.elementAt(3);
                    String attend = (String) vec.elementAt(4);
                    String status = (String) vec.elementAt(5);
    
                    crb.setHalls(halls);
                    crb.setEvent(event);
                    crb.setDateTime1(date_time1);
                    crb.setDateTime2(date_time2);
                    crb.setAttend(attend);
                    crb.setStatus(status);
    
                    crv.addElement(crb);
                }
                session.setAttribute("BookRequestBeanVector", crv);
                sendPage(request, response, "/viewbook.jsp");
            }
        }
    
        void sendPage(HttpServletRequest req, HttpServletResponse res, String fileName) throws ServletException, IOException {
            // Get the dispatcher; it gets the main page to the user
            RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(fileName);
    
            if (dispatcher == null) {
                System.out.println("There was no dispatcher");
                // No dispatcher means the html file could not be found.
                res.sendError(res.SC_NO_CONTENT);
            } else {
                dispatcher.forward(req, res);
            }
        }
    
        public void destroy() {
            mvcConnectionPool.closeAllConnections();
        }
    }
    and this is my BookRequestBean
    Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package mvc;
    
    /**
     *
     * @author rbk
     */
    public class BookRequestBean {
    
        private String requestID = "";
        private String login = "";
        private String halls = "";
        private String event = "";
        private String date_time1 = "";
        private String date_time2 = "";
        private String attend = "";
        private String status = "";
    
        public void setRequestID(String requestID) {
            this.requestID = requestID;
        }
    
        public String getRequestID() {
            return requestID;
        }
    
        //*********************************************
        public void setLogin(String login) {
            this.login = login;
        }
    
        public String getLogin() {
            return login;
        }
    
        //*********************************************
        public void setHalls(String halls) {
            this.halls = halls;
        }
    
        public String getHalls() {
            return halls;
        }
    
        //*********************************************
        public void setEvent(String event) {
            this.event = event;
        }
    
        public String getEvent() {
            return event;
        }
    
        //*********************************************
        public void setDateTime1(String date_time1) {
            this.date_time1 = date_time1;
        }
    
        public String getDateTime1() {
            return date_time1;
        }
    
        //*********************************************
        public void setDateTime2(String date_time2) {
            this.date_time2 = date_time2;
        }
    
        public String getDateTime2() {
            return date_time2;
        }
    
        //*********************************************
        public void setAttend(String attend) {
            this.attend = attend;
        }
    
        public String getAttend() {
            return attend;
        }
    
        //*********************************************
        public void setStatus(String status) {
            this.status = status;
        }
    
        public String getStatus() {
            return status;
        }
        //*********************************************
    }
    Last edited by cax; 12-02-2011 at 04:31 PM.

  • #2
    Regular Coder
    Join Date
    Feb 2008
    Location
    Edinburgh - Scotland
    Posts
    107
    Thanks
    0
    Thanked 12 Times in 12 Posts
    So what is the problem,,,the page renders but no tables are drawn?

    That suggests that your crbv vector has a size of 0...I would check that and determine if it is 0, why is it 0!

    That would be a possible reason for it not drawing the table.

  • #3
    cax
    cax is offline
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the crbv vector size is not 0...i have tried the same code in the admin site and it works just fine...but for user site i did not manage to work it out..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •