FileDocCategorySizeDatePackage
MovieInfo.javaAPI DocExample3639Sun Mar 02 09:44:56 GMT 2003com.mediamania.appserver

MovieInfo

public class MovieInfo extends HttpServlet

Fields Summary
PersistenceManagerFactory
persistenceManagerFactory
PersistenceManager
pm
Constructors Summary
Methods Summary
public voiddestroy()
Destroys the servlet.

    
protected voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Handles the HTTP GET method.

param
request servlet request
param
response servlet response

        processRequest(request, response);
    
protected voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Handles the HTTP POST method.

param
request servlet request
param
response servlet response

        processRequest(request, response);
    
protected java.lang.StringformatMovieInfo()

        StringBuffer result = new StringBuffer();
        Extent movies = pm.getExtent(Movie.class, true);
        Iterator it = movies.iterator();
        while (it.hasNext()) {
            result.append("<P>");
            Movie movie = (Movie)it.next();
            result.append(movie.getDescription());
        }
        return result.toString();
    
public java.lang.StringgetServletInfo()
Returns a short description of the servlet.

        return "Movie Information";
    
public voidinit()

        try {
            ServletContext ctx = getServletContext();
            InputStream in = ctx.getResourceAsStream("WEB-INF/pmf.properties");
            Properties props = new Properties();
            props.load(in);
            persistenceManagerFactory = 
                JDOHelper.getPersistenceManagerFactory(props);
        } catch (IOException ex) {
            throw new ServletException("Unable to load PMF properties.", ex);
        } catch (JDOException ex) {
            throw new ServletException("Unable to create PMF resource.", ex);
        } catch (Exception ex) {
            throw new ServletException("Unable to initialize.", ex);
        }
        
    
protected voidprocessRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Processes requests for both HTTP GET and POST methods.

param
request servlet request
param
response servlet response

        pm = persistenceManagerFactory.getPersistenceManager();
        response.setContentType("text/html");
        java.io.PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet</title>");
        out.println("</head>");
        out.println("<body>");
        out.print(formatMovieInfo());
        out.println("</body>");
        out.println("</html>");
        out.close();
        pm.close();