下面列出了javax.servlet.Servlet#init ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
}
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);
}
}
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()));
}
}
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;
}