I Have a file called authenticate.jsp :
<%@page import=" java.sql.*, java.util.*,java.io.*" %>
<%
Connection con = null;
Statement stmt = null;
ResultSet fireman = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String connectionString = "jdbc:mysql://localhost:3306/firedept?"
+ "user=xxx&password=xxx";
con = DriverManager.getConnection(connectionString);
stmt = con.createStatement();
fireman = stmt.executeQuery("SELECT username,password,first,last,user_type FROM fireman");
String user = request.getParameter("user");
String pass = request.getParameter("pass");
while (fireman.next())
{
if (user.equals(fireman.getString("username")) && pass.equals(fireman.getString("password")))
{
String first = fireman.getString("first");
String last = fireman.getString("last");
String user_type = fireman.getString("user_type");
session.setAttribute("fname", fireman.getString("first"));
%>
<script type="text/javascript">
sessionStorage.setItem("first", "<%=first%>" )
sessionStorage.setItem("last", "<%=last%>" )
sessionStorage.setItem("user_type", "<%=user_type%>" )
</script>
<%
response.sendRedirect("home.jsp"); // remember to change to jsp
break;
}
}
response.sendRedirect("login.jsp"); // remember to change to jsp
}
catch (Exception ex) {
out.write(ex.getMessage());
}
finally {
stmt.close();
con.close();
}
%>
And another file which is a header.jspf file and its used in other pages via <%@include file="header.jspf" %>
<div class="logged" id="login_tag">You are logged in : </div>
<script>
document.getElementById("login_tag").innerHTML = "You are logged in as : "+sessionStorage.getItem("first");
</script>
When i try to get the "first" value from the sessionStorage in the header it just returns null, what is the problem here ? This is the same project and the files are in the same folder running on Apache server. Thanks :).