关于使用Struts时eclipse中出现There is no Action mapped for namespace / and action name的问题

好久没有写博客,这次的问题困扰了三天。。决定一定要记录一下

<?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>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
  <package name="basicstruts"  namespace="/" extends="struts-default">
 
  <action name="showProduct" class="com.how2java.action.ProductAction" method="show">
    <result name="show">show.jsp</result>
  </action>    
 
</package>

如上是struts.xml文件,这个文件一定要直接放在动态web项目下的src目录里面

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    <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>
 
</web-app>

以上是web.xml文件。

值得注意的是eclipse的project中,通常会将编译好的文件放在build-classes中,如果这样,run on server之后控制台是会报错的。

所以要进行设置。右击项目——properties——Java build Path——source——browse,将编译目录改成WebContent-webinf-classes.

在进行如上操作之后,访问http://localhost:8080/struts/showProduct 仍然报错404 ,There is no Action..................

检查文件夹发现,实际上webinf下面的classes是空的,也就是说并没有编译。

所以针对没有编译的问题,解决办法如下

鼠标左击 选中工程-横向菜单Project-build Automatically的对勾点掉,然后build all,然后再点上build automatically的对勾,重启eclipse,即可成功访问原地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值