session ending

Discussions

Web tier: servlets, JSP, Web frameworks: session ending

  1. session ending (4 messages)

    I want to end the session and close the database connection .I am using session.invalidate method after this I want to redirect to a html page say first page.where can I handle this?

    Threaded Messages (4)

  2. session ending[ Go to top ]

    I used this in the body of a doGet or doPost:

    // Payment received -- invalIdate the session
            session.invalidate();
            
            // set content type header before accessing the Writer
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            
            // then write the response
            out.println("<html>" +
                        "<head><title> Receipt </title>" +
                        "<meta http-equiv=\"refresh\"
    content=\"4; url=" +
                        "http://localhost/Fathom.html;\">" +
                        "</head>" +
                        
                        "<body bgcolor=\"#FFFFFF\">" +
                        "<center>" +
                        "<hr> <br> &nbsp;" +
                        "<h1>" +
                        "<font size=\"+3\" color=\"red\">Fathom </font>" +
                        "<font size=\"+3\" color=\"black\">Communications</font>" +
                        "</h1>" +
                        "</center>" +
                        "<br> &nbsp; <hr> <br> &nbsp;");
            
            out.println("<h3>Thank you for purchasing your solution from us " +
                        request.getParameter("cardname") +
                        "<p>Please shop with us again soon!</h3>" +
                        
                        "<p><i>This page automatically resets.</i>" +

                        "</body></html>");
            out.close();
  3. session ending[ Go to top ]

    Please ignore this one above, I don't know why this printed out.
  4. session ending[ Go to top ]

    .. or you could do that like

    session.invalidate();
    response.sendRedirect("page.html");

    if you write a separate html-file you dont have to write all those "out.print();" -lines
  5. session ending[ Go to top ]

    I used this in the body of a doGet or doPost:

    // Payment received -- invalIdate the session
       session.invalidate();
            
    // set content type header before accessing the Writer
       response.setContentType("text/html");
       PrintWriter out = response.getWriter();
            
       // then write the response
       out.println("<html>" +
          "<head><title> Receipt </title>" +
          "<meta http-equiv=\"refresh\"content=\"4; url=" +
          "http://localhost/Fathom.html;\">" +
          "</head>" +
          "<body bgcolor=\"#FFFFFF\">" +
          "<center>" +
          "<hr> <br> &nbsp;" +
          "<h1>" +
          "<font size=\"+3\" color=\"red\">Fathom</font>" +
          "<font size=\"+3\"
              color=\"black\">Communications</font>" +
          "</h1>" +
          "</center>" +
          "<br> &nbsp; <hr> <br> &nbsp;");
            
       out.println("<h3>Thank you for purchasing your
               solution from us " +
           request.getParameter("cardname") +
           "<p>Please shop with us again soon!</h3>" +
           "<p><i>This page automatically resets.</i>" +
           "</body></html>");
           out.close();

    Then close out your database in the destroy method:

    public void destroy() {
        try{
    connection.close();
        }
        catch (Exception e) {
    System.out.println("Database close failed");
    System.out.println(e.toString());
        }
    }