I've implemented a JSP function that manages user login by verifying their name and password input. However, even if the user enters incorrect information, they can still view the page. I want to hide all content on the page so that the user cannot see it while a countdown timer redirects them.
I'm unsure of how to achieve this within an if/else statement in JSP.
Below is the relevant section of JSP code along with the divs I need 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>