您的位置:首页 > 移动开发

ssh web项目出现错误There is no Action mapped for namespace [/] and action name [login] associate解决办法

2017-11-17 23:26 519 查看
在我学习写项目的时候,为了正确规范我们的代码,会把jsp文件放在WEB-INF 下面,一般不会放在
WEB-INF 下面,因为放在 WEB-INF 下面在浏览器直接能够访问,如果我们不想让用户直接访问就会选择放在WEB-INF
下面。

用MyEclipse 运行项目出现错误“There
is no Action mapped for namespace [/] and action name [login] associate”。

 解决办法:

1.检查“struts.xml”配置文件字母有没有错误,大小写是否正确。

2.确保struts.xml文件在src目录下(struts.xm位于src下是为了编译后能找到struts配置文件)。

3.检查web项目输出路径。右键web项目选择“properties”



4.按照提示步骤检查项目输出路径是否正确。

5.如果上述问题都没有错误,那就检查下“struts.xml”配置文件(标记为红色的要注意,加上最好)。

<?xml
version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC

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

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

<struts>

    <package name="shop" extends="struts-default" namespace="/">

        <!-- 配置访问首页的Action -->

        <action name="index" class="indexAction">

            <result name="indexok">/WEB-INF/jsp/index.jsp</result>

        </action>

    </package>

</struts>

6.如果都加上之后还是报错误的话。那就要注意下了,我们的是ssh框架整合,struts里面的Action
的 Class是交给了spring来管理。

struts.xml配置文件:

<?xml
version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC

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

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

<struts>

    <package name="shop" extends="struts-default" namespace="/">

        <!-- 配置访问首页的Action -->

        <action name="index" class="com.hry.index.action">

            <result name="indexok">/WEB-INF/jsp/index.jsp</result>

        </action>

    </package>

</struts>

Spring配置文件:

<!-- 事务管理 -->

    <!-- 事务管理器 -->

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">

        <property name="sessionFactory" ref="sessionFactory" />

    </bean>

    <!-- 开启注解事务 -->

    <tx:annotation-driven transaction-manager="transactionManager"/>

    

    <!-- ==============================Action配置========================== -->

    <!-- 访问首页的Action -->

    <bean id="indexAction" class="com.hry.shop.index.action.IndexAction" scope="prototype">

    

    </bean>

不知道大家有没有发现,我Spring里面配置的是(
scope="prototype"也不能够缺少,看看自己的是否加上去):

<bean
id="indexAction"class="com.hry.shop.index.action.IndexAction" scope="prototype">

而“
struts.xml”里面接收得是:

 <action
name="index" class="com.hry.index.action"> 明显两个不一样,一个是Spring里面我们自己定义的“indexAction”,一个却是我们这个Action的路径,这也是造成错误的一个小细节。

基本上也就是这问题了,如果还有其他问题可以联系本人,我们共同探讨。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐