response.sendRedirect won't work JSP

Discussion in 'Java' started by nino9stars@yahoo.com, Jan 30, 2007.

  1. Guest

    Hello,

    I am trying to make a "Please wait..." loading screen using JSP. I
    sort of have it working (based on bits of information I found in the
    groups), but not really. I created an IFrame to open in the JSP file
    that displays the "Please wait..." animated gif. Now, in my code I
    want to do some work and then redirect to the next page.

    Problem is, when I keep the out.println(""); in the code, the "Please
    wait..." sign works fine and the page is still loading, however it
    won't redirect...

    On the same token, if I remove the out.println(""); from the code,
    then it does the work and redirects, but doesn't show the "Please
    wait..." sign???

    Any way to get both of these working together? Have it show the
    "Please wait..." sign while it does the work, AND redirect to the next
    step when it's done?

    Here is my latest attempt:

    <HTML>
    <HEAD>
    <TITLE>Loading Data...</TITLE>
    <META http-equiv="Pragma" content="no-cache">
    <META http-equiv="Cache-Control" content="no-cache">
    <META http-equiv="Expires" content="-1">
    <% //Make sure we DO NOT cache these pages
    response.addHeader("Pragma", "no-cache");
    response.addHeader("Expires", "-1");
    %>
    <LINK rel="stylesheet" href="styles.css" type="text/css">
    </HEAD>

    <BODY bgcolor="#FFFFFF" text="#404040" leftmargin="0" topmargin="0"
    marginwidth="0" marginheight="0">

    <iframe src="loadingScreen.html" width="500" height="500"></iframe>

    </BODY>
    </HTML>

    <%@ page import="java.io.*" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.lang.*" %>
    <%@ page import="javax.servlet.*" %>

    <%
    session = request.getSession(true);
    //session time-out clause
    if ((session.isNew()) | (session.getAttribute("db") == null)) {
    session.invalidate();
    response.sendRedirect("TimeOut");
    return;
    }

    String url = ""+session.getAttribute("db")+"";
    String driver = ""+session.getAttribute("dr")+"";
    String sqlu = ""+session.getAttribute("u")+"";
    String sqlp = ""+session.getAttribute("p")+"";

    String db_query = "";
    ResultSet db_result;

    Connection con;
    Statement stmt;

    try {
    Class.forName(driver);
    } catch (java.lang.ClassNotFoundException e) {
    out.println("ClassNotFoundException " + e.getMessage());
    } catch (Exception e) {
    out.println("driver not "+e.getMessage()); }

    try {
    con = DriverManager.getConnection(url,""+sqlu+"",""+sqlp+"");
    stmt = con.createStatement();

    boolean redirectMe = false;

    for (int x=0; x < 3; x++) {
    db_query = "select fname, lname, track_id from USERS right join
    TRACKS on track_id=user_id";
    db_result = stmt.executeQuery(db_query);
    while (db_result.next()) {
    //out.println("");
    }
    redirectMe = true;
    }

    if (redirectMe) {
    response.sendRedirect("sHome.jsp");
    stmt.close();
    con.close();
    return;
    }

    stmt.close();
    con.close();

    } catch (SQLException ex) {
    out.println("SQLException " + ex.getMessage());
    }
    %>

    Thanks for any help... I greatly appreciate it...

    Nino Skilj
     
    , Jan 30, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas
    Replies:
    6
    Views:
    3,238
    Andrea Desole
    Feb 15, 2005
  2. carlisle411
    Replies:
    4
    Views:
    12,391
    John C. Bollinger
    Feb 28, 2005
  3. Jeano
    Replies:
    5
    Views:
    7,300
    Orilg
    Oct 13, 2010
  4. ohaya
    Replies:
    0
    Views:
    4,118
    ohaya
    Jun 30, 2005
  5. Replies:
    1
    Views:
    823
    chris brat
    Jun 2, 2006
Loading...

Share This Page