在用eclipse做struts1项目时,配置都ok了。可是一运行就报java.lang.NullPointerException: Module 'null' not found.错。
代码如下;
web.xml
1 <servlet> 2 <servlet-name>action</servlet-name> 3 <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> 4 <init-param> 5 <param-name>config</param-name> 6 <param-value>/WEB-INF/struts-config.xml</param-value> 7 </init-param> 8 </servlet> 9 <servlet-mapping> 10 <servlet-name>action</servlet-name> 11 <url-pattern>*.do</url-pattern> 12 </servlet-mapping>
struts-config.xml:
1 <struts-config> 2 <form-beans> 3 <form-bean name="loginForm" type="com.actionform.LoginForm" /> 4 </form-beans> 5 <action-mappings> 6 <action path="/login" type="com.action.LoginAction" name="loginForm" input="/index.jsp" 7 scope="request"> 8 <forward name="success" path="/success.jsp" /> 9 </action> 10 </action-mappings> 11 </struts-config>
jsp页面:
1 <html:form action="login.do" method="post"> 2 <html:text property="username"></html:text> 3 <br> <html:submit value="Submit"></html:submit> 4 </html:form>
action和actionform都是ok的。
配置和好后,程序无任何语法异常。但是在我打开index.jsp页面的时候程序抛出了空指针异常
java.lang.NullPointerException: Module 'null' not found.抛出这个异常的时候我们知道这是由于Tomcat并未加载
ActionServlet 以致Jsp界面使用Struts中的<html:text property="">程序抛出异常.
1 Oct 10, 2015 4:38:15 PM org.apache.catalina.core.StandardWrapperValve invoke 2 SEVERE: Servlet.service() for servlet jsp threw exception 3 java.lang.NullPointerException: Module 'null' not found. 4 at org.apache.struts.taglib.TagUtils.getModuleConfig(TagUtils.java:755) 5 at org.apache.struts.taglib.TagUtils.getModuleConfig(TagUtils.java:735) 6 at org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:818) 7 at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:488) 8 at org.apache.jsp.index_jsp._jspx_meth_html_005fform_005f0(index_jsp.java:83) 9 at org.apache.jsp.index_jsp._jspService(index_jsp.java:54) 10 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) 11 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 12 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331) 13 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329) 14 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265) 15 at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 16 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) 17 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188) 18 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) 19 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174) 20 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 21 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117) 22 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108) 23 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174) 24 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874) 25 at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665) 26 at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528) 27 at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81) 28 at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) 29 at java.lang.Thread.run(Unknown Source)
异常延伸:
一、这个异常就牵扯到web.xml 的<load-on-startup></load-on-startp>
二、那么这个标签有什么用了?
这个标签有着很重要的用途<load-on-startup>(在这里可以放置0-5之间的整数)</load-on-startp>
1 <servlet> 2 <servlet-name>action</servlet-name> 3 <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> 4 <init-param> 5 <param-name>config</param-name> 6 <param-value>/WEB-INF/struts-config.xml</param-value> 7 </init-param> 8 <load-on-startup>1</load-on-startup> 9 </servlet>
三、0-5 是web容器控制Tomcat告诉Tomcat按怎样的顺序去执行init()方法加载Servlet(程序中可能会有多个Serlvet)如果没有在web.xml中使用这个标签或者参数的为负数 那么Tomcat将不自动加载这个Servlet。上诉错误就是因
为没有在web.xml中配置<load-on-startup>标签
四、另外<load-on-startup>中的参数越小那么优先级也就越高