this is my JSP , it'll get the username and email using session.getAttribute("key") method.
The problem is, If someone tries to open this page directly , without logging in , Then the values of the variable username and email should be null , and the user should be redirected to another page.
But instead I'm getting a nullPointerExcepetion just as I try to run this page without beginning the session , aka , going directly to this page without logging in using the url.
Here's the code.
The problem is, If someone tries to open this page directly , without logging in , Then the values of the variable username and email should be null , and the user should be redirected to another page.
But instead I'm getting a nullPointerExcepetion just as I try to run this page without beginning the session , aka , going directly to this page without logging in using the url.
Here's the code.
Code
<%@page import="supportServlets.MyBeans"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body bgcolor='#c1c1c1'>
<%
HttpSession studentSession=request.getSession(false);
String username=(String)studentSession.getAttribute("username");
String email=(String)studentSession.getAttribute("email");
if(username.equals(null)||email.equals(null))
{
MyBeans.setFlag("no");
response.sendRedirect("studentLogin.jsp");
}
%>
<jsp:include page="headerLogo.jsp"/>
<form action="mainQuizPage">
<center>
<div style="width: 700px; background-color: whitesmoke">
<center>
<h2>Welcome <%=username%></h2>
<br>
</center>
</div>
</center>
</form>
<jsp:include page="footerLogo.jsp"/>
</body>
</html>
