Results 1 to 2 of 2
  1. #1
    lisalu22 is offline Member
    Join Date
    Feb 2010
    Posts
    1
    Rep Power
    0

    Default JSP partially renders sometimes

    Most of the time, the JSP renders correctly. But every now and then, it doesn't render completely. It always cuts off the html code at the same point...a very random point in the code may I add. It cuts off before I call the getFaculty() method.

    I thought it may have been a problem with not closing the connection and/or statement. But, in that case, the page probably wouldn't render at all (blank page). This never happens, though.

    This is running on a Tomcat server. When the page doesn't render completely, I just reload the app, and it works again (for about a week until it happens again). Is there something that is reset by Tomcat when it is reloaded? Can I code this in the JSP?

    I have other pages that are EXACTLY the same, but they always render completely. However, this is the first page that comes up, so it is viewed the most.

    Another thing is that the jspInit() method isn't always called. That is why I check to make sure there is a connection in the getFaculty() method. If not, it will connect. Just thought I'd clarify that in case some of you were wondering.

    Any help would be greatly appreciated! Thanks!


    [CODE]
    <%
    letter = request.getParameter("letter");
    research = request.getParameter("research");
    status = request.getParameter("status");
    faan = request.getParameter("faan");

    String jspPath = getServletContext().getRealPath(request.getServlet Path());
    File jspFile = new File(jspPath);
    Long lastModified = jspFile.lastModified();
    java.util.Date date = new java.util.Date(lastModified);
    %>
    <%!
    public void jspInit() {
    try {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
    conn = DriverManager.getConnection(REMOVED FOR PRIVACY);
    stmt = conn.createStatement();
    } catch (Exception ex) { }
    }
    public void jspDestroy() {
    try {
    stmt.clearBatch();
    stmt.close();
    conn.close();
    } catch (Exception ex) { }
    }

    ArrayList facs = new ArrayList();
    Faculty fac = null;
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    String letter = null;
    String research = null;
    String status = null;
    String faan = null;

    void getFaculty() throws ServletException {
    try {
    try {
    rs = stmt.executeQuery("select * from faculty where primkey='_'");
    rs.close();
    } catch (SQLException ex) {
    conn = DriverManager.getConnection(REMOVED FOR PRIVACY);
    stmt = conn.createStatement();
    }

    facs = new ArrayList();
    if (letter!=null) {
    rs = stmt.executeQuery("select * from FACULTY where lname like '"+letter+"%' order by lname");
    } else if (research!=null) {
    rs = stmt.executeQuery("select * from FACULTY where research is not null and datalength(research)>0 order by lname");
    } else if (status!=null) {
    rs = stmt.executeQuery("select * from FACULTY where status='"+status+"' order by lname");
    } else if (faan!=null) {
    rs = stmt.executeQuery("select * from FACULTY where credentials like '%FAAN%' order by lname");
    } else {
    rs = stmt.executeQuery("select * from FACULTY order by lname");
    }
    while (rs.next()) {
    fac = new Faculty();
    fac.setFname(rs.getString("fname"));
    fac.setMi(rs.getString("mi"));
    fac.setLname(rs.getString("lname"));
    fac.setPhone(rs.getString("phone"));
    fac.setPrimkey(rs.getString("primkey"));
    fac.setStatus(rs.getString("status"));
    fac.setImage(rs.getString("image"));
    facs.add(fac);
    }
    rs.close();

    try {
    stmt.clearBatch();
    stmt.close();
    conn.close();
    } catch (Exception ex) { }

    } catch (SQLException ex) { throw new ServletException(ex); }
    }
    %>
    [CODE]

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    366
    Rep Power
    6

    Default

    If you don't mind mate i think you should rewrite your code completely.

    Using <% %> scriptlets n JSP is very bad habit.

    Move code to your java classes.

    Use servlet to receive request and receive params.
    Write a class that works with DB.
    Write class that creates response with data taken from DB class and your app logic.
    Let servlet direct your response to JSP.
    Try to use JSP just to take params for servlet or to display end result,
    don't put java code in it!

    This way everything is where it is supposed to be
    you can easily debug and log what you need
    so no more phantom pages for you mate.

    good luck!

Similar Threads

  1. Replies: 3
    Last Post: 01-12-2009, 12:20 AM

Tags for this Thread

Posting Permissions

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