非常SB的struts2.x异常(下篇)

(接上篇文章)

2010-9-25 10:36:54 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class

org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 14 in XML

document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid;

nested exception is org.xml.sax.SAXParseException: Content is not allowed in trailing

section.
      
2010-9-25 10:44:15 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
Class: com.opensymphony.xwork2.spring.SpringObjectFactory
File: SpringObjectFactory.java
Method: getClassInstance
Line: 220 - com/opensymphony/xwork2/spring/SpringObjectFactory.java:220:-1


Caused by: java.lang.NullPointerException


左思右想还是想不到为什么,换了一些关键词,搜到了:

“““
最佳答案 7481086_582 - 大副 十二级

你可能把不要的包也导进去了或是哪个必需的包没导入,以下是必需包: 
Spring包(9个): 
commons-dbcp.jar、commons-pool.jar、spring.jar、spring-beans.jar、 
spring-context.jar、spring-core.jar、spring-dao.jar、 
spring-hibernate3.jar、spring-web.jar。

struts2.0包(6个):commons-logging-api-1.1.jar、freemarker-2.3.8.jar 
ognl-2.6.11.jar、struts2-core-2.0.8.jar、 
struts2-spring-plugin-2.0.11.2.jar、xwork-2.0.3.jar

hibernate包:myeclipse工具自动添加生成导入。 
还有就是数据库驱动包。

”””

无奈之下,我把所有的包又导了进去,因为在所有的包中,里面含有了部分需要的spring的包。还把
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> 
补了回去。

这次错误只剩下一个!!!!!!!!!!!!!


2010-9-25 12:36:24 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
2010-9-25 12:36:31 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
Class: org.apache.struts2.osgi.OsgiConfigurationProvider
File: OsgiConfigurationProvider.java
Method: init
Line: 70 - org/apache/struts2/osgi/OsgiConfigurationProvider.java:70:-1
        at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:428)
        at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher

(InitOperations.java:69)
        at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init

省略若干行…………

(DefaultConfiguration.java:214)
        at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration

(ConfigurationManager.java:66)
        at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration

(Dispatcher.java:371)
        at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:415)
        ... 27 more
2010-9-25 12:36:31 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext

在网上找到了两种答复
“““
原因没有找到,不过解决方法找到了,删除struts2-osgi-plugin-2.1.8.jar
, struts2-osgi-admin-bundle-2.1.8.jar

”””

“““
<filter>

    <filter-name>struts2</filter-name>

    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>

    <init-param>

        <param-name>configProviders</param-name>

        <param-value>org.apache.struts2.osgi.OsgiConfigurationProvider</param-value>

    </init-param>

</filter>

”””

我试了一下第二种:
Caused by: java.lang.ClassCastException:

org.apache.struts2.osgi.OsgiConfigurationProvider cannot be cast to

com.opensymphony.xwork2.config.ConfigurationProvider
    
动了一下脑筋~~~~~
改成了:
                   <filter>
                                    <!-- 定义核心Filter的名字 -->
                                  <filter-name>struts2</filter-name>
      <!-- 定义核心Filter的实现类 -->
        <filter-

class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-

class>
      <init-param>
          <param-name>configProviders</param-name>
                                      <param-

value>com.opensymphony.xwork2.config.ConfigurationProvider</param-value>
                                  </init-param>
      </filter>

异常更多了~~~~~~
~~~~(>_<)~~~~ 
改了回去~~~~~~

试一下第一种~~~~~~~~~

一样出错:
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of

element 'Context'.

找不到定义?还是声明?

我把
<context:annotation-config />
<context:component-scan base-package="com.service*" />
删了。


还是很多错误~~~~~~~~
崩溃了~~~~~~~~~~~~~~
啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊~~~~~~~~~

+_+!!

下个插件试试~~~~~~~
http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=23467


外面下着细雨~~~~~~中秋节刚过完后的秋雨~~~~~~~~~
哥下午没课~~~~~~~~其实哥很纠结~~~~~~~~~~~~~~~~~
哥大四了~~~~~~~~~~哥得找工作的~~~~~~~~~~~~~~~~~
哥分心了~~~~~~~~~~继续学习!继续继续!!!!!!


下完安装后,运行它里面自带的helloworld~~~~~~~
发现提示没有META-INF下的context.xml,于是从其他地方复制了一个过来,加以修改。
发现可以运行了~~~~

= =!你大爷的!!!!!它里面的tomcat日志也会报错!而且跟我之前报的那些错误差不多!!!

o(╯□╰)o
怎么可以这样捏?

它的程序可以正常运行嘢!

对比了一下我的程序后,我进行了一些改动:
1、删去apllicationContext.xml
2、把struts.xml从WEB-INF下的classes移出到源包下的缺省包中
3、把web.xml中的listener去掉
4、将我之前设定的Struts2.2.1库的包修改为:
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/commons-fileupload-1.2.1.jar!/
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/commons-io-1.3.2.jar!/
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/commons-logging-1.0.4.jar!/
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/freemarker-2.3.16.jar!/
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/ognl-3.0.jar!/
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/struts2-core-2.2.1.jar!/
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/xwork-core-2.2.1.jar!/

(这里我必须提示一下:我所测试的内容是关于struts2.2.1的,不与hibernate、spring它们整合,

之前犯了很多错误,一方面是自己经验不足,另一方面是受到网上的人的解答的误导)


看来插件确实是个好东西~~~~~~~~~~~
(*^__^*)


在netbeans的输出栏,一个是run,一个是apache tomcat,还有一个是apache tomcat 日志。
看来以后可以不管“apache tomcat 日志”了。


页面还是显示404错误,找不到/testStruts2/Login.jsp(路径没出错哦!!!)。
仔细检查struts.xml后发现:      <!-- Struts 2的Action必须放在指定的包空间下定义 -->

于是将原来的package标签的name的值改为actionPackage (自己定义的包名)
即<package name="actionPackage" extends="struts-default">

留意一下:“““
插件中struts.xml是这样的:
<struts>
    <include file="example.xml"/>
    <!-- Configuration for the default package. -->
    <package name="default" extends="struts-default">
    </package>
</struts>

难道表示example.xml的定义?


而example.xml是这样的:
<struts>
    <package name="example" namespace="/example" extends="struts-default">
        <action name="HelloWorld" class="example.HelloWorld">
            <result>/example/HelloWorld.jsp</result>
        </action>
    </package>
</struts>
”””

先不管那么多,清理并生成后运行,生成失败可能是因为有未结束的java.exe占用了资源,打开任务

管理器消除即可。

貌似“清理并生成”是经常要做的事情,好像是在修改了xml之后需要???

出现了:Caused by: java.lang.IllegalArgumentException: Javassist library is missing in

classpath! Please add missed dependency!

二话不说,补回包。


啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

成功了!!!!!!!!!!!!!!!

肉牛满面!!!!!!!!!!!!!!

大肥羊!!!!!!!!!!!!!!!

~~~~~~~~》_《~~~~~~~~~

呜呜呜~~~~~~~
总结一下:

零、在netbeans的输出栏,一个是run,一个是apache tomcat,还有一个是apache tomcat 日志。
以后不要被“apache tomcat 日志”里的exception迷惑到了。

一、使用netbeans6.9.1进行struts2.2.1开发时,可以下载插件。也可以直接下载那个struts2-

2.2.1-all文件。
解压后必需包为:
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/commons-fileupload-1.2.1.jar!/
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/commons-io-1.3.2.jar!/
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/commons-logging-1.0.4.jar!/
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/freemarker-2.3.16.jar!/
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/ognl-3.0.jar!/
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/struts2-core-2.2.1.jar!/
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/xwork-core-2.2.1.jar!/
jar:file:/F:/struts2-2.2.1-all/struts-2.2.1/lib/javassist-3.7.ga.jar!/

(javassist-3.7.ga.jar在哪找的?看前面!!!)

二、无需applicationContext.xml、web.xml中无需listener(即

org.springframework.web.context.ContextLoaderListener)
估计在使用spring时才会用到~~~~


三、不知道struts.xml是不是必需放到缺省包下面?

四、需要有/META-INF/context.xml、/WEB-INF/web.xml、/缺省包/struts.xml。

其中web.xml为:(注意filter-class的值,注意标签的顺序!!!)
<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
          <!-- 定义Struts 2的FilterDispatcher的Filter -->
                                  <filter>
                                    <!-- 定义核心Filter的名字 -->
                                  <filter-name>struts2</filter-name>
      <!-- 定义核心Filter的实现类 -->
        <filter-

class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-

class>
      </filter>

                                 <!-- FilterDispatcher用来初始化Struts 2并且处理所有的

Web请求 -->
     <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>


    </web-app>


context.xml为:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/testStruts2"/>


struts.xml为:(注意package的name!!!!!)
<?xml version="1.0" encoding="UTF-8"?>


<!-- 指定Struts 2配置文件的DTD信息 -->

<!DOCTYPE struts PUBLIC

        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

        "http://struts.apache.org/dtds/struts-2.0.dtd">

<!-- struts是Struts 2配置文件的根元素 -->

<struts>

                                 <!-- Struts 2的Action必须放在指定的包空间下定义 -->

                                 <package name="actionPackage" extends="struts-default">

                                    <!-- 定义login的Action,该Action的实现类为

actionPackage.LoginAction类 -->

                                  <action name="Login"

class="actionPackage.LoginAction">

                                        <!-- 定义处理结果和资源之间映射关系。 -->

                                   <result name="error">/error.jsp</result>

                                   <result name="success">/welcome.jsp</result>       

                                  </action>

                                  </package>

</struts>

五、注意所有xml的标签不要写错!!!多一个<、>都不行!!!!标签内多一个空格都不行!!!

注意不要写错!!!!!!!!注意<>要与</>匹配!!!!!!!

六、教训:以后多用插件,另外那些chm电子书经常错漏百出,以后切不可尽信之!!!!!

弄了好久~~~~~~~
囧!!!!!!!
o(╯□╰)o~~~~~~~~~~

不要迷恋哥~~~哥只是一个杯具~~~~

(完)


后记:如果想使用<s:datetimepicker>标签,须导入struts2-dojo-plugin.jar

解决方法(三步走): 
1、在jsp文件中加入<%@ taglib uri="/struts-dojo-tags" prefix="sx"%>和<sx:head/>

2、将<s:datetimepicker label="XXXX" name="XXXX"></s:datetimepicker>改为<sx:datetimepicker label="XXXX" name="XXXX"></sx:datetimepicker>

3、将struts2-dojo-plugin.jar拷贝到/web-inf/lib下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值