
How fined session is new or old ?

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CheckSession extends HttpServlet{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.println("Check the session is new or old<br>");
HttpSession session = request.getSession();
if(session.isNew()){
pw.println("You have created a new session");
}
else{
pw.println("Session already exists");
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.