struts2与spring整合报错,求救啊!

YangMacgrady 2010-06-28 04:26:14
部署好启动tomcat时一直出这个错:
严重: Dispatcher initialization failed
Unable to load configuration. - bean - jar:file:/D:/tomcat-6.0.20/webapps/OA/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:47:178

一堆错误都由上面那个引起。。。。

严重: Error filterStart
2010-6-28 16:14:39 org.apache.catalina.core.StandardContext start
严重: Context [/OA] startup failed due to previous errors

配置文件没问题啊,包引入也没问题,都在lib下。
弄一下午崩溃了……
--------------------------------------------------------------------------------------------------------
web.xml----------

<?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">

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

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

<filter-mapping>
<filter-name>struts2</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.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<package name="struts2" extends="struts-default">
<action name="Login" class="loginAction">
<result name="success">/result.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>

</struts>
--------------------------------------------------------------------------------
applicationContext.xml----

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<bean id="loginService" class="com.struts2.service.impl.LoginServiceImpl"></bean>

<bean id="loginAction" class="com.struts2.action.LoginAction" scope="prototype">
<property name="loginServeci" ref="loginService"></property>
</bean>
</beans>
...全文
398 43 打赏 收藏 转发到动态 举报
写回复
用AI写文章
43 条回复
切换为时间正序
请发表友善的回复…
发表回复
tomb_zx 2011-08-10
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 yangmacgrady 的回复:]

但是出这个错了:There is no Action mapped for namespace / and action name
怎么搞的啊,我都配置好了的。。。
请帮忙看下啊,大家,我在线等-----
login.jsp里面的form:
<body>
<s:form action="Login" method="post">
<s:textfield n……
[/Quote]

action不方请求名么:action="请求名!方法名"
袭烽 2010-06-29
  • 打赏
  • 举报
回复
记得把分全部给我,不然以后不给你帮你,还耽误我吃饭时间
袭烽 2010-06-29
  • 打赏
  • 举报
回复
首先楼主应该排除包的问题,查看是否用到了commons-fileupload-1.2.1.jar 和commons-io-1.3.2.jar,避免jar包缺失或者冲突

其次排除tomcat缓存问题,清理工程class下所有文件和tomcat的work下的所有文件,刷新重新部署

接着注意struts2 的namespace属性用于定义该包的命名空间。该属性可以不配置,如果不指定该属性,默认的命名空间为“”(空字符串)。当某个包指定了命名空间后,该包下所有的Action处理的URL应该是: namespace+Action的名称,但是
struts 2.1.6 有个bug,如果你的配置设置为 <constant name="struts.devMode" value="true" />
或者tomcat路径有空格(好像是这个)就会出这个问题 ,你把它改成<constant name="struts.devMode" value="false" />并且最好指定一个namespace名称

最后如果以上办法都不可行,我建议你去网上下载传智播客 struts2 入门视频和源码,这里粘贴一段能用的配置代码:
----bean.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>
<package name="employee" namespace="/employee" extends="struts-default">
<action name="list" class="employeeAction">
<result name="list">/WEB-INF/page/employee.jsp</result>
</action>
<action name="manage_*" class="employeeManageAction" method="{1}">
<result name="add">/WEB-INF/page/employeeAdd.jsp</result>
</action>
</package>
</struts>

----web.xml----
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
<!-- 对Spring容器进行实例化 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

----employee.jsp----

<body>
<s:form action="manage_add" namespace="/employee" method="post">
用户名:<s:textfield name="employee.username"/><br/>
密码:<s:textfield name="employee.password"/><br/>
性别:<s:radio list="#{'MAN':'男','WOMEN':'女'}" listKey="key" listValue="value" name="employee.gender"/>
<input type="submit" value="保存"/>
</s:form>
</body>
2010-06-29
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 yangmacgrady 的回复:]

There is no Action mapped for namespace / and action name
小弟完全没辙了
[/Quote]
在struts的配置文件中 加上namespace
Pbulic 2010-06-29
  • 打赏
  • 举报
回复
学习了
同光和尘 2010-06-29
  • 打赏
  • 举报
回复
filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>


貌似这里有问题
YangMacgrady 2010-06-29
  • 打赏
  • 举报
回复
[Quote=引用 31 楼 steel_sun 的回复:]
引用 8 楼 haijun286972766 的回复:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
改成
<filter>
<filter-name>struts2</f……
[/Quote]
已经改过filter试验多次。。。
YangMacgrady 2010-06-29
  • 打赏
  • 举报
回复
[Quote=引用 30 楼 dushouxian 的回复:]
<bean id="loginAction" class="com.struts2.action.LoginAction" scope="prototype">
<property name="loginServeci" ref="loginService"></property>
</bean>


spring的配置文件中的loginAction的property的name是……
[/Quote]
我后来改了,依然一样的错误。。。。
steel_sun 2010-06-29
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 haijun286972766 的回复:]
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
改成
<filter>
<filter-name>struts2</filter-name>
<filter-class>or……
[/Quote]


这个类似正确
dushouxian 2010-06-29
  • 打赏
  • 举报
回复
<bean id="loginAction" class="com.struts2.action.LoginAction" scope="prototype">
<property name="loginServeci" ref="loginService"></property>
</bean>


spring的配置文件中的loginAction的property的name是不是错了啊?
YangMacgrady 2010-06-29
  • 打赏
  • 举报
回复
[Quote=引用 24 楼 happysmhzp 的回复:]
关于struts2你加的jar文件有哪些呢?
[/Quote]
/OA/WebRoot/WEB-INF/lib/commons-logging-1.0.4.jar
/OA/WebRoot/WEB-INF/lib/freemarker-2.3.15.jar
/OA/WebRoot/WEB-INF/lib/ognl-2.7.3.jar
/OA/WebRoot/WEB-INF/lib/xwork-core-2.1.6.jar
/OA/WebRoot/WEB-INF/lib/struts2-core-2.1.8.1.jar
/OA/WebRoot/WEB-INF/lib/struts2-spring-plugin-2.1.8.1.jar
/OA/WebRoot/WEB-INF/lib/spring.jar
/OA/WebRoot/WEB-INF/lib/commons-fileupload-1.2.1.jar
YangMacgrady 2010-06-29
  • 打赏
  • 举报
回复
[Quote=引用 26 楼 person_java 的回复:]
<action name="Login" class="loginAction">
是不是这一行出错啊,改为<action name="Login" class="LoginAction">
试一试。如果有包的话包名.类名,估计是这里的错误,你看看!!
[/Quote]
也试验了,依然无法改变结果。。。。
两天了。。。
person_java 2010-06-29
  • 打赏
  • 举报
回复
可以把你的项目发个我不?271127400@qq.com
NetMatrix 2010-06-29
  • 打赏
  • 举报
回复
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
貌似这里有问题,struts2.1.3之后都用
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
YangMacgrady 2010-06-29
  • 打赏
  • 举报
回复
[Quote=引用 38 楼 shimiso 的回复:]
记得把分全部给我,不然以后不给你帮你,还耽误我吃饭时间
[/Quote]
我到现在也没吃饭,哥们……不过谢谢你。

源代码,配置都没问题
问题完全解决,真想仰天大骂句“靠”,再次感谢所有童鞋的帮助!!!!!
dushouxian 2010-06-29
  • 打赏
  • 举报
回复
搞不懂 把你的源码拷贝过来调试 没出现你的问题
forever_ai 2010-06-28
  • 打赏
  • 举报
回复
路过
jf
person_java 2010-06-28
  • 打赏
  • 举报
回复
<action name="Login" class="loginAction">
是不是这一行出错啊,改为<action name="Login" class="LoginAction">
试一试。如果有包的话包名.类名,估计是这里的错误,你看看!!
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 haijun286972766 的回复:]
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
改成
<filter>
<filter-name>struts2</filter-name>
<filter-clas……
[/Quote]
....................
happysmhzp 2010-06-28
  • 打赏
  • 举报
回复
关于struts2你加的jar文件有哪些呢?
加载更多回复(23)

67,516

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧