本文整理了Java中javax.servlet.Servlet.init()
方法的一些代码示例,展示了Servlet.init()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Servlet.init()
方法的具体详情如下:
包路径:javax.servlet.Servlet
类名称:Servlet
方法名:init
[英]Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
The servlet container calls the init
method exactly once after instantiating the servlet. The init
method must complete successfully before the servlet can receive any requests.
The servlet container cannot place the servlet into service if the init
method
ServletException
init
方法一次。init
方法必须成功完成,servlet才能接收任何请求。init
方法ServletException
代码示例来源:origin: spring-projects/spring-framework
/**
* Initialize the wrapped Servlet instance.
* @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
*/
@Override
public void afterPropertiesSet() throws Exception {
if (this.servletClass == null) {
throw new IllegalArgumentException("'servletClass' is required");
}
if (this.servletName == null) {
this.servletName = this.beanName;
}
this.servletInstance = ReflectionUtils.accessibleConstructor(this.servletClass).newInstance();
this.servletInstance.init(new DelegatingServletConfig());
}
代码示例来源:origin: jersey/jersey
@Override
public void init(ServletConfig config) throws ServletException {
wrappedServlet.init(new ServletConfigWrapper(config));
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof Servlet) {
ServletConfig config = this.servletConfig;
if (config == null || !this.useSharedServletConfig) {
config = new DelegatingServletConfig(beanName, this.servletContext);
}
try {
((Servlet) bean).init(config);
}
catch (ServletException ex) {
throw new BeanInitializationException("Servlet.init threw exception", ex);
}
}
return bean;
}
代码示例来源:origin: org.springframework/spring-webmvc
/**
* Initialize the wrapped Servlet instance.
* @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
*/
@Override
public void afterPropertiesSet() throws Exception {
if (this.servletClass == null) {
throw new IllegalArgumentException("'servletClass' is required");
}
if (this.servletName == null) {
this.servletName = this.beanName;
}
this.servletInstance = ReflectionUtils.accessibleConstructor(this.servletClass).newInstance();
this.servletInstance.init(new DelegatingServletConfig());
}
代码示例来源:origin: Atmosphere/atmosphere
/**
* Initialize the {@link Filter}
*
* @throws javax.servlet.ServletException
*/
public void init() throws ServletException {
for (FilterConfigImpl f : filters) {
if (f != null) {
f.getFilter().init(f);
}
}
if (servlet != null) {
servlet.init(configImpl);
}
}
代码示例来源:origin: org.springframework/spring-webmvc
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof Servlet) {
ServletConfig config = this.servletConfig;
if (config == null || !this.useSharedServletConfig) {
config = new DelegatingServletConfig(beanName, this.servletContext);
}
try {
((Servlet) bean).init(config);
}
catch (ServletException ex) {
throw new BeanInitializationException("Servlet.init threw exception", ex);
}
}
return bean;
}
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
@Override
protected void doPortalInit() throws Exception {
ServletContext servletContext = servletConfig.getServletContext();
ClassLoader classLoader = (ClassLoader)servletContext.getAttribute(
PluginContextListener.PLUGIN_CLASS_LOADER);
String servletClass = servletConfig.getInitParameter("servlet-class");
servlet = (Servlet)InstanceFactory.newInstance(
classLoader, servletClass);
servlet.init(servletConfig);
}
代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-jaxws
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);
}
}
代码示例来源:origin: spring-projects/spring-framework
servlet.init(new MockServletConfig(servletContext, "myHandler"));
代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel
@Override
protected void doPortalInit() throws Exception {
ServletContext servletContext = servletConfig.getServletContext();
ClassLoader classLoader = (ClassLoader)servletContext.getAttribute(
PluginContextListener.PLUGIN_CLASS_LOADER);
String servletClass = servletConfig.getInitParameter("servlet-class");
_subcontext = servletConfig.getInitParameter("sub-context");
if (_subcontext == null) {
_subcontext = getServletName();
}
servlet = (Servlet)InstanceFactory.newInstance(
classLoader, servletClass);
if (!(servlet instanceof HttpServlet)) {
throw new IllegalArgumentException(
"servlet-class is not an instance of " +
HttpServlet.class.getName());
}
servlet.init(servletConfig);
PortalDelegatorServlet.addDelegate(_subcontext, (HttpServlet)servlet);
}
代码示例来源:origin: pentaho/mondrian
private static Servlet getServlet(
String cbClassName,
String dataSourceText,
Map<List<String>, Servlet> cache)
throws ServletException
{
final List<String> key =
Collections.singletonList(
dataSourceText);
Servlet servlet = cache.get(key);
if (servlet != null) {
return servlet;
}
MockServletContext servletContext = new MockServletContext();
MockServletConfig servletConfig = new MockServletConfig(servletContext);
servletConfig.addInitParameter(
XmlaServlet.PARAM_CALLBACKS, cbClassName);
servletConfig.addInitParameter(
XmlaServlet.PARAM_CHAR_ENCODING, "UTF-8");
servletConfig.addInitParameter(
XmlaServlet.PARAM_DATASOURCES_CONFIG,
"inline:" + dataSourceText);
servlet = new MondrianXmlaServlet();
servlet.init(servletConfig);
if (cache != null) {
cache.put(key, servlet);
}
return servlet;
}
代码示例来源:origin: com.atlassian.jira/jira-core
@Override
public void init(ServletConfig config) throws ServletException
{
displayChart.init(config);
}
代码示例来源:origin: apache/cxf
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);
}
}
代码示例来源:origin: apache/felix
@Override
public void init(final ServletConfig config) throws ServletException
{
super.init(config);
dispatcherServlet.init(config);
getHttpServiceController().register(config.getServletContext(), serviceRegProps);
}
代码示例来源:origin: io.github.factoryfx/jettyFactory
public void update(Servlet servlet, Collection<BasicRequestHandler> basicRequestHandlers){
try {
servlet.init(this.servlet.getServletConfig());
} catch (ServletException e) {
throw new RuntimeException(e);
}
this.servlet=servlet;
this.basicRequestHandler = basicRequestHandlers==null? Collections.emptyList():new ArrayList<>(basicRequestHandlers);
}
代码示例来源:origin: httpunit/httpunit
synchronized Servlet getServlet() throws ClassNotFoundException, InstantiationException, IllegalAccessException, ServletException {
if (_servlet == null) {
Class servletClass = Class.forName( getClassName() );
_servlet = (Servlet) servletClass.newInstance();
String servletName = _servletName != null ? _servletName : _servlet.getClass().getName();
_servlet.init( new ServletUnitServletConfig( servletName, WebApplication.this, getInitParams() ) );
}
return _servlet;
}
代码示例来源:origin: org.kohsuke.httpunit/httpunit
synchronized Servlet getServlet() throws ClassNotFoundException, InstantiationException, IllegalAccessException, ServletException {
if (_servlet == null) {
Class servletClass = Class.forName( getClassName() );
_servlet = (Servlet) servletClass.newInstance();
String servletName = _servletName != null ? _servletName : _servlet.getClass().getName();
_servlet.init( new ServletUnitServletConfig( servletName, WebApplication.this, getInitParams() ) );
}
return _servlet;
}
代码示例来源:origin: javaee/grizzly
/**
* Starts {@link Servlet} instance of this {@link OSGiServletHandler}.
*
* @throws ServletException If {@link Servlet} startup failed.
*/
public void startServlet() throws ServletException {
configureServletEnv();
servletInstance.init(getServletConfig());
}
代码示例来源:origin: stackoverflow.com
String jspClassName = findJspClassForJSP("your.jsp");
Class jspClass = Class.forName(jspClassName);
Servlet jspServlet = (Servlet)jspClass.newInstance();
MyServletRequest req = new MyServletRequest();
MyServletResponse resp = new MyServletResponse();
jspServlet.init();
jspServlet.service(req, resp);
jspServlet.destroy();
String results = reps.getContent();
代码示例来源:origin: OpenNMS/opennms
@Override
public void init()
throws ServletException
{
String name = "servlet_" + getId();
ServletConfig config = new ServletConfigImpl(name, getContext(), getInitParams());
this.servlet.init(config);
}
内容来源于网络,如有侵权,请联系作者删除!