On index page, jsp is not checking whether session is exists or not and continued to next page and after refreshing it shows same page with session attribute.
Actually in mycode if loop is not working what is problem
Please help out.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>login Page</title>
</head>
<body>
<h1>index page</h1>
<jsp:include page="/check" />
</body>
</html>
Servlet code:
package reg;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class check extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
//request.getRequestDispatcher("link.html").forward(request, response);
out.print("hello check servlet<br>");
HttpSession nsession=request.getSession(false);
if(nsession == null) {
String name=(String)nsession.getAttribute("name");
out.print("Hello, "+name+" Welcome to Profile");
request.getRequestDispatcher("/adminhome.jsp").include(request, response);
} else {
out.print("Please login first");
request.getRequestDispatcher("/login.jsp").include(request, response);
}
out.close();
}
}