在servlet的配置当中,<load-on-startup>5</load-on-startup>的含义是: 标记容器是否在启动的时候就加载这个servlet。 当值为0或者大于0时,表示容器在应用启动时就加载这个servlet; 当是一个负数时或者没有指定时,则指示容器在该servlet被选择时才加载。 正数的值越小,启动该servlet的优先级越高。 Servlet specification: 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. example: <servlet> <servlet-name>initservlet</servlet-name> <servlet-class>com.bb.eoa.util.initServlet</servlet-class> <init-param> <param-name>log4j-init-file</param-name> <param-value>config/log.properties</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet>
在配置struts应用时,我发现如果不配置<load-on-startup>2</load-on-startup>
<servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet>
那么当在JSP页面里面使用struts jstl时会报错误:
如logon.jsp页面如下:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html:html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <html:form action="logon.do"> UserName:<html:text property="userName" ></html:text> Password:<html:text property="password"></html:text> <html:submit>submit</html:submit> </html:form> </body> </html:html>
如果不配置<load-on-startup>2</load-on-startup>
那么运行时报错如下:
java.lang.NullPointerException: Module 'null' not found. org.apache.struts.taglib.TagUtils.getModuleConfig(TagUtils.java:755) org.apache.struts.taglib.TagUtils.getModuleConfig(TagUtils.java:735) org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:818) org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:488) org.apache.jsp.Logon_jsp._jspx_meth_html_005fform_005f0(Logon_jsp.java:138) org.apache.jsp.Logon_jsp._jspx_meth_html_005fhtml_005f0(Logon_jsp.java:111) org.apache.jsp.Logon_jsp._jspService(Logon_jsp.java:80) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
所以解决在使用struts jstl时出现以上错误时,应在web.xml中配置<load-on-startup>2</load-on-startup>