javax.servlet.Servlet#init ( )源码实例Demo

下面列出了javax.servlet.Servlet#init ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Tomcat8-Source-Read   文件: Tomcat.java
@Override
public synchronized Servlet loadServlet() throws ServletException {
    if (singleThreadModel) {
        Servlet instance;
        try {
            instance = existing.getClass().getConstructor().newInstance();
        } catch (ReflectiveOperationException e) {
            throw new ServletException(e);
        }
        instance.init(facade);
        return instance;
    } else {
        if (!instanceInitialized) {
            existing.init(facade);
            instanceInitialized = true;
        }
        return existing;
    }
}
 
源代码2 项目: knopflerfish.org   文件: ServletRegistration.java
public ServletRegistration(final String alias, final Servlet servlet,
                           Dictionary<String, String> parameters,
                           final HttpContext httpContext,
                           final ServletContextManager contextManager,
                           final Registrations registrations)
  throws ServletException
{
  if (parameters == null) {
    parameters = new Hashtable<String, String>();
  }

  if (parameters.get(HttpUtil.SERVLET_NAME_KEY) == null) {
    parameters.put(HttpUtil.SERVLET_NAME_KEY, servlet.getClass().getName());
  }

  this.contextManager = contextManager;
  this.registrations = registrations;

  // Fail fast if servlet already registered!
  registrations.addServlet(servlet);

  final ServletContext context =
    contextManager.getServletContext(httpContext, null);
  final ServletConfig config = new ServletConfigImpl(parameters, context);
  servlet.init(config);

  dispatcher =
    new RequestDispatcherImpl(alias, servlet, httpContext,
                              lastModificationDate);
}
 
public void setServletConfig(ServletConfig servletConfig) {
    try {
        shadowCxfServlet = (Servlet)servletClass.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
    try {
        shadowCxfServlet.init(servletConfig);
    } catch (ServletException ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
}
 
源代码4 项目: lemon   文件: ServletFilter.java
public void init(FilterConfig filterConfig) throws ServletException {
    for (Map.Entry<UrlPatternMatcher, Servlet> entry : servletMap
            .entrySet()) {
        Servlet servlet = entry.getValue();
        servlet.init(new ProxyServletConfig(filterConfig
                .getServletContext()));
    }
}
 
源代码5 项目: packagedrone   文件: JspServletWrapper.java
public Servlet getServlet()
    throws ServletException, IOException, ClassNotFoundException
{
    if (reload) {
        synchronized (this) {
            // Synchronizing on jsw enables simultaneous loading
            // of different pages, but not the same page.
            if (reload) {
                // This is to maintain the original protocol.
                destroy();
                
                try {
                    servletClass = ctxt.load();
                    theServlet = (Servlet) servletClass.newInstance();
                } catch( IllegalAccessException ex1 ) {
                    throw new JasperException( ex1 );
                } catch( InstantiationException ex ) {
                    throw new JasperException( ex );
                }
                
                theServlet.init(config);

                if (!firstTime) {
                    ctxt.getRuntimeContext().incrementJspReloadCount();
                    // Fire the jspReloadedEvent probe event
                    if (jspProbeEmitter != null) {
                        jspProbeEmitter.jspReloadedEvent(jspUri);
                    }
                }

                reload = false;

                // Fire the jspLoadedEvent probe event
                if (jspProbeEmitter != null) {
                    jspProbeEmitter.jspLoadedEvent(jspUri);
                }
            }
        }
    }
    return theServlet;
}