The load-on-startup element indicates that this servlet should be loaded (instantiated and have its init() called) on the startup of the web application. The optional contents of these element must be an integer indicating the order in which the servlet should be loaded. If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses. If the value is a positive integer or 0, the container must load and initialize the servlet as the application is deployed. The container must guarantee that servlets marked with lower integers are loaded before servlets marked with higher integers. The container may choose the order of loading of servlets with the same load-on-start-up value.
load-on-startup 元素在web应用启动的时候指定了servlet被加载的顺序,它的值必须是一个整数。如果它的值是一个负整数或是这个元素不存在,那么容器会在该servlet被调用的时候,加载这个servlet。如果值是正整数或零,容器在配置的时候就加载并初始化这个serlvet,容器必须保证值小的优先加载。如果数值相等,容器可以自动选择先加载。
package com.sample.base;
import java.io.File;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import org.apache.log4j.Logger;
public class Boot extends HttpServlet {
private static final long serialVersionUID = 4177925985208589275L;
private static final Logger logger = Logger.getLogger(Boot.class);
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
logger.info("Server booting...");
logger.info("OS Name:" + System.getProperty("os.name"));
logger.info("OS Version:" + System.getProperty("os.version"));
logger.info("OS Architecture:" + System.getProperty("os.arch"));
logger.info("CPU Maybe:" + System.getProperty("sun.cpu.isalist"));
logger.info("JRE Version:" + System.getProperty("java.version"));
logger.info("JRE Runtime:" + System.getProperty("java.runtime.version"));
java.net.URL url = getClass().getClassLoader().getResource("/");
String SERVER_PATH = new File(url.getPath()).getParent() + File.separator;
logger.info("SERVER_PATH:" + SERVER_PATH);
try {
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void destroy() {
super.destroy();
}
}
分享到:
相关推荐
Servlet 配置load-on-startup的作用详解 load-on-startup是Servlet配置中一个重要的参数,它用于指定Servlet的加载顺序和时机。在Servlet的配置文件web.xml中,我们可以通过设置<load-on-startup>标签来控制Servlet...
<load-on-startup>1</load-on-startup> <servlet-mapping> <servlet-name>chapter2</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> ``` - **load-on-startup**:该属性用于指示容器在启动时...
二、load-on-startup元素详解 load-on-startup元素在web应用启动时指定servlet的加载顺序。值为整数,若为负数或省略,则在需要时加载;若为正数或零,则在应用启动时加载,数值越小,优先级越高。 三、配置顺序与...
<load-on-startup>1</load-on-startup> ``` - 作用:如果设置了 `<load-on-startup>` 元素,则表示该Servlet将在Web应用启动时自动加载。数字值表示加载顺序,值越小优先级越高。 通过以上解析可以看出,`web....
load-on-startup 元素用于指定 Servlet 的加载顺序。当值为 0 或者大于 0 时,表示容器在应用启动时就加载这个 Servlet。正数的值越小,启动该 Servlet 的优先级越高。 filter 元素 filter 元素用于配置过滤器。...
<load-on-startup>1</load-on-startup> <servlet-mapping> <servlet-name>Connector</servlet-name> <url-pattern>/fckeditor/editor/filemanager/connectors/*</url-pattern> </servlet-mapping> ``` 2. *...
<load-on-startup>1</load-on-startup> ``` **2. 集成Struts框架** Struts框架的集成涉及到在`web.xml`中配置`ActionServlet`,它是Struts的核心组件,用于处理HTTP请求。此外,还需指定Struts的配置文件`struts...
<load-on-startup>1</load-on-startup> <servlet-mapping> <servlet-name>SampleServlet</servlet-name> <url-pattern>/sample</url-pattern> </servlet-mapping> ``` - **`<servlet>`**: 定义一个Servlet。 -...
<load-on-startup>1</load-on-startup> <servlet-mapping> <servlet-name>myServlet</servlet-name> <url-pattern>/myservlet</url-pattern> </servlet-mapping> <!-- 配置会话超时 --> <session-config> ...
<load-on-startup>1</load-on-startup> ``` #### 6. 声明过滤器 过滤器用于拦截客户端请求并在请求到达目标资源之前进行预处理,以及在响应发送回客户端之前进行后处理。声明过滤器需要使用`<filter>`元素。 **...
<load-on-startup>1</load-on-startup> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> ``` 这里的`<init-param>`元素用于指定Spring MVC的...
<load-on-startup>1</load-on-startup> <servlet-mapping> <servlet-name>CKFinderServlet</servlet-name> <url-pattern>/ckfinder/connector/*</url-pattern> </servlet-mapping> ``` 配置完成后,CKFinder会...
<load-on-startup>100</load-on-startup> <servlet-name>SOAPMonitorService</servlet-name> <servlet-class>org.apache.axis.monitor.SOAPMonitorService</servlet-class> <init-param> <param-name>...
<load-on-startup>1</load-on-startup> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> ``` 2. **Spring-MVC配置文件**: 配置HandlerMapping、...