FileDocCategorySizeDatePackage
SaveState.javaAPI DocExample1679Tue Jan 25 10:45:14 GMT 2000None

SaveState

public class SaveState extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();

    ServletContext context = getServletContext();
    Enumeration names = context.getServletNames();
    while (names.hasMoreElements()) {
      String name = (String)names.nextElement();
      Servlet servlet = context.getServlet(name);

      out.println("Trying to save the state of " + name + "...");
      out.flush();
      try {
        Method save = servlet.getClass().getMethod("saveState", null);
        save.invoke(servlet, null);
        out.println("Saved!");
      }
      catch (NoSuchMethodException e) {
        out.println("Not saved.  This servlet has no saveState() method.");
      }
      catch (SecurityException e) {
        out.println("Not saved.  SecurityException: " + e.getMessage());
      }
      catch (InvocationTargetException e) {
        out.print("Not saved.  The saveState() method threw an exception: ");
        Throwable t = e.getTargetException();
        out.println(t.getClass().getName() + ": " + t.getMessage());
      }
      catch (Exception e) {
        out.println("Not saved.  " + e.getClass().getName() + ": " +
                    e.getMessage());
      }

      out.println();
    }
  
public java.lang.StringgetServletInfo()

    return "Calls the saveState() method (if it exists) for all the " +
           "currently loaded servlets";