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