FileDocCategorySizeDatePackage
ShowSession.javaAPI DocExample1627Mon May 01 14:41:50 BST 2000None

ShowSession

public class ShowSession extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

        response.setContentType("text/html");
        PrintWriter out = response.getWriter(  );

        out.println(
          "<html><head><title>Show Session</title></head><body>");
        HttpSession session = request.getSession(  );

        out.println("<h1>In this session:</h1><ul>");
        String [] names = session.getValueNames(  );
        for (int i=0; i< names.length; i++)
            out.println(
              "<li>"+names[i]+" = "+session.getValue( names[i] ));

        // add new name-value to session
        String name = request.getParameter("Name");
        if ( name != null ) {
            String value = request.getParameter("Value");
            session.putValue( name, value );
        }

        out.println(
          "</ul><p><hr><h1>Add String</h1>"
          + "<form method=\"POST\" action=\""
          + request.getRequestURI(  ) +"\">"
          + "Name: <input name=\"Name\" size=20><br>"
          + "Value: <input name=\"Value\" size=20><br>"
          + "<br><input type=\"submit\" value=\"Submit\"></form>"
        );

        out.close(  );
    
public voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

        doGet( request, response );