vendredi 4 décembre 2015

How do I Hide Div's and Redirect to a HTML page using If/else Statements?

So I have JSP function that handles a users login to the site by checking if they have entered the right name and password

Currently regardless the user can still see the page I want to make it redirect back to the login after say 3 seconds from the if/else statements AND hide everything on the page so the user cant see it while it counts down

Im just not sure how to do that inside and if/else statement in jsp

Heres the JSP part of file along with the divs I ant to hide

<body id="Body">
    <%@ page import ="java.sql.*" %><%@ page import ="javax.sql.*" %><%String user = request.getParameter("userid");
        session.putValue("userid", user);
        String pwd = request.getParameter("pwd");
        Class.forName("com.mysql.jdbc.Driver");
        java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:8081/socusers", "root", "");
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("select * from users where user_id='" + user + "'");
        String message = "";
        if (rs.next()) {
            if (rs.getString(2).equals(pwd)) {
                message = "Welcome " + user;
            } else {
                message = "Invalid password try again";
                //Redirect after 3 seconds back to login and hide all divs
            }
        } else {
            message = "Invalid user try again";
            //Redirect after 3 seconds back to login and hide all divs
        }
        out.println(message);


    %>

<center>
    <div class="container chat-signin">
        <form class="form-signin">
            <h2><i>NCI Soc Talk</i></h2>
            <label for="nickname">Enter Nickname:</label> <input type="text" placeholder="Nickname" id="nickname">
            <div>
                <label for="chatroom">Select Chatroom</label> <select size="1" id="chatroom">
                    <option value="1">Gaming Soc</option>
                    <option value="2">Pokemon Soc</option>
                    <option value="3">Fashion Soc</option>
                    <option value="4">Other Soc</option>
                </select>
            </div>
            <button type="submit" id="enterRoom">Sign in</button>
        </form>
    </div>

    <div class="container chat-wrapper">
        <form id="do-chat">
            <h2></h2>
            <h4></h4>
            <table id="response" ></table>
            <fieldset>
                <legend>Enter your message..</legend>
                <div>
                    <input type="text" placeholder="Your message..." id="message" style="height:60px; width:1000px;"/>
                    <br />
                    <input type="submit" value="Send message" />
                    <button type="button" id="Exit-room">Exit Room</button>
                </div>
            </fieldset>
        </form>
    </div>
</center>

Aucun commentaire:

Enregistrer un commentaire