FileDocCategorySizeDatePackage
ForumServlet.javaAPI DocExample2393Sun Sep 02 14:59:06 BST 2001com.oreilly.forum.servlet

ForumServlet

public class ForumServlet extends HttpServlet
The single servlet in the discussion forum.

Fields Summary
private ReqHandlerRegistry
registry
Constructors Summary
Methods Summary
public voiddestroy()
Closes all database connections. This method is invoked when the Servlet is unloaded.

        super.destroy();
        DBUtil.closeAllConnections();
    
protected voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

        ReqHandler rh = this.registry.getHandler(request);
        Renderer rend = rh.doGet(this, request, response);
        rend.render(this, request, response);
    
protected voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

        ReqHandler rh = this.registry.getHandler(request);
        Renderer rend = rh.doPost(this, request, response);
        rend.render(this, request, response);
    
public voidinit(javax.servlet.ServletConfig sc)
Registers all request handlers and sets up the ForumConfig object.

        super.init(sc);

        // get initialization parameters from the deployment
        // descriptor (web.xml)
        String jdbcDriverClassName = sc.getInitParameter(
                "jdbcDriverClassName");
        String databaseURL = sc.getInitParameter(
                "databaseURL");
        String adapterClassName = sc.getInitParameter(
                "adapterClassName");
        ForumConfig.setValues(jdbcDriverClassName,
                databaseURL, adapterClassName);

        try {
            // load all request handlers
            this.registry = new ReqHandlerRegistry(new HomeReqHandler());
            this.registry.register(new PostMsgReqHandler());
            this.registry.register(new ViewMonthReqHandler());
            this.registry.register(new ViewMsgReqHandler());
        } catch (Exception ex) {
            log(ex.getMessage(), ex);
            throw new UnavailableException(ex.getMessage(), 10);
        }