使用Tomcat 5.0配置Struts2.1.6时出现异常
我是 Struts 2 的新手。在使用 Tomcat 5 配置 Struts 2 时,我收到以下异常。我搜索了很多论坛,但没有一个给出任何解决方案。
这是异常堆栈跟踪:
java.lang.NullPointerException at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:203) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyResultType(XmlConfigurationProvider.java:511) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addResultTypes(XmlConfigurationProvider.java:482) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:438) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:265) at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111) at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:189) at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403) at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
这是我的 web.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
这是 struts.xml 文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml"/>
<!-- Add packages here -->
<package name="default" extends="struts-default">
<action name="HelloWorld" class="com.sid.HelloWorldAction">
<result>/pages/login.jsp</result>
</action>
</package>
</struts>
这是我的类路径上的 jar 列表:
commons-beanutils-1.7.0.jar commons-collections-3.2.jar commons-digester-1.8.jar commons-fileupload-1.2.1.jar commons-io-1.3.2.jar commons-lang-2.4.jar commons-logging-1.0.4.jar commons-net-1.4.1.jar commons-validator-1.3.0.jar displaytag-1.1.jar displaytag-export-poi-1.1.jar freemarker-2.3.13.jar ibatis-2.3.4.726.jar iText-2.1.3.jar jstl.jar log4j-1.2.15.jar mail-1.3.3.jar ognl-2.6.11.jar poi-3.0-rc4-20070503.jar spring.jar standard.jar struts2-convention-plugin-2.1.6.jar struts2-core-2.1.6.jar struts2-spring-plugin-2.0.11.1.jar struts2-tiles-plugin-2.1.6.jar tiles-api-2.0.6.jar tiles-core-2.0.6.jar tiles-jsp-2.0.6.jar xwork-2.1.2.jar
I am new to Struts 2. While configuring Struts 2 with Tomcat 5, I received the following exception. I have searched many forums but none gave any solutions.
Here is the exception stack trace:
java.lang.NullPointerException at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:203) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyResultType(XmlConfigurationProvider.java:511) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addResultTypes(XmlConfigurationProvider.java:482) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:438) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:265) at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:111) at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:189) at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403) at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
Here is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Here is struts.xml file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml"/>
<!-- Add packages here -->
<package name="default" extends="struts-default">
<action name="HelloWorld" class="com.sid.HelloWorldAction">
<result>/pages/login.jsp</result>
</action>
</package>
</struts>
Here is the list of jars I have on my classpath:
commons-beanutils-1.7.0.jar commons-collections-3.2.jar commons-digester-1.8.jar commons-fileupload-1.2.1.jar commons-io-1.3.2.jar commons-lang-2.4.jar commons-logging-1.0.4.jar commons-net-1.4.1.jar commons-validator-1.3.0.jar displaytag-1.1.jar displaytag-export-poi-1.1.jar freemarker-2.3.13.jar ibatis-2.3.4.726.jar iText-2.1.3.jar jstl.jar log4j-1.2.15.jar mail-1.3.3.jar ognl-2.6.11.jar poi-3.0-rc4-20070503.jar spring.jar standard.jar struts2-convention-plugin-2.1.6.jar struts2-core-2.1.6.jar struts2-spring-plugin-2.0.11.1.jar struts2-tiles-plugin-2.1.6.jar tiles-api-2.0.6.jar tiles-core-2.0.6.jar tiles-jsp-2.0.6.jar xwork-2.1.2.jar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您使用 spring 插件时,尝试将 Spring 上下文加载器侦听器添加到您的 web.xml 中
As you are using the spring plugin try adding the Spring context loader listner to you web.xml
典型的 struts-2 错误日志记录很差。您认为他们会花费额外的时间检查空值并给出有意义的错误消息吗?没有。欢迎来到开源。 Struts2 在安装和运行方面非常令人沮丧。无论如何,如果你不打算配置 spring-plugin,请将其删除。
Typical struts-2 poor error logging. You'd think they'd spend extra time checking nulls and giving a meaningful error msg? Nope. Welcome to opensource. Struts2 is pretty frustrating when it comes to getting it installed and working. Anyhow, take out the spring-plugin if you're not going to configure it.