Struts2中关于"There is no Action mapped for namespace / and action name"的总结

作者: 孤旅者

今天在调试一个基础的Struts2框架小程序。总是提示"There is no Action mapped for namespace / and action name"的错误。上网查询后发现这是一个初学者经常碰到的问题,导致错误的原因主要有两种。总结如下:

      一、struts.xml文件错误。这种错误又分为以下几种:1,struts.xml文件名错误。一定要注意拼写问题;2,struts.xml文件放置路径错误。一定要将此文件放置在src目录下。编译成功后,要确认是否编译到classes目录中;3,struts.xml文件内容错误。下面给出一个正确的struts.xml文件以供参考。注意背景色部分。

<?xml version="1.0" encoding="UTF-8" ?>
<span style="background-color: rgb(0, 204, 204);"><!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd"></span>

<struts>
    <package name="default" namespace="/" extends=<span style="background-color: rgb(0, 204, 204);">"struts-default"</span>>
        <action name="login" class="com.wanggc.struts2.sample.Struts2Action">
        <result name="success">/jsp/result.jsp</result>
        </action>
    </package>
</struts>


 
二、如果排除了struts.xml文件的问题,还有一种可能就是,在web.xml文件中的<welcome-file>信息中是否配置了自己工程的启动页面。如果没有配置,地址栏中要输入完成的url,如: 
http://localhost:8080/Struts2Sample/jsp/login.jsp 
,后面的资源详细信息不输入的时候也会报这个错误,我就是栽在这个问题上的(^_^)。 

<pre name="code" class="html"><?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
	<display-name>struts2</display-name>
	<welcome-file-list>
		<welcome-file>login.jsp</welcome-file>
	</welcome-file-list>
  
 	<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>


 


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值