Login.jsp
<%
/* Getting Database connection*/
Connection connection = ConnectionFactory.getInstance()
.getConnection();
if (connection == null) {
System.out.print("Error in getting DB connection");
}
/* requesting user login credentials*/
String login_name = request.getParameter("username");
String login_pass = request.getParameter("password");
if ((login_name != null && login_name.trim() != "")
|| (login_pass != null && login_pass.trim() != "")) {
String query = "SELECT USER_NAME,PASSWORD from MEMBERS where USER_NAME='"
+ login_name + "'";
PreparedStatement ps = connection.prepareStatement(query);
ResultSet rs = ps.executeQuery();
String USER_NAME = null;
String PASSWORD = null;
while (rs.next()) {
USER_NAME = rs.getString("USER_NAME");
PASSWORD = rs.getString("PASSWORD");
}
//verifying with database
if ((USER_NAME.equals(login_name) && PASSWORD
.equals(login_pass))) {
//starting session
session.setAttribute("UserName", USER_NAME);
System.out.println(session.getCreationTime());
out.print("<head> <meta http-equiv=\"Refresh\" content=\"0;url=./home.jsp\" > </head>");
} else {
out.println("Login Failed");
}
} else {
out.println("Please Enter Your Credentials");
%>
<jsp:include page="./login.html"></jsp:include>
<%
}
%>
Home.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Home</title>
</head>
<body>
Hi, <%= session.getAttribute("UserName") %>
<% System.out.println(session.getCreationTime());%>
</body>
</html>
Home.jsp displaying Hi,null
why?
I understood that the home .jsp is creating new session but how to make use of existing session? Can any body help to resolve this please?