eclipse中配置struts2出现There is no Action mapped for namespace [/] and action name [Login] associated wi

下午在eclipse中配置struts2时报:

There is no Action mapped for namespace [/] and action name [Login] associated with context path [/eprint]

错误

做如下检查:

1、确保struts.xml文件名大小写正确:struts.xml

2、确保struts.xml文件在src目录下(很重要!后面就着重说这个)

附:

web.xml文件内容

示例:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
	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_3_0.xsd">
  <display-name></display-name>	
  
   <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>
  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app> 


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="default" namespace="/" extends="struts-default">
		<action name="LoginAction" class="com.xxx.control.LoginAction">
			<!-- 定义逻辑视图和物理资源之间的映射 -->
			<result name="error">index.jsp</result>
			<result name="success">/WEB-INF/main.jsp</result>
		</action>
	</package>
</struts>


index.jsp:

 <s:form action="LoginAction" namespace="/">
			<s:textfield name="username" label="username"></s:textfield>
			<s:password name="password" label="password"></s:password>
			<div id="login_button">
			    <input type="submit" value="login"/> 
			</div>
			<div  id="register_button">
			    <input type="button" value="register"/>
			</div>

       </s:form>


反复确认之后,还是没找到错误

找度娘,好多种解决方案,木有一个可以解决我的问题的

最后发现是我的struts.xml是在src目录下,没有任何疑问

但是我的编译后classes文件默认却是在build目录下

不在WEB-INF下.......

这样它是找不到struts.xml文件的,报如上错误,也是情有可原的

 

最后,明确一点,struts.xm位于src下是为了编译后能找到struts配置文件,确保其在WEB-INF下才是根本!!!

更改eclipse web 项目默认编译输出路径:

eclipse中只能针对项目更改,因为其默认的是build目录下的,只能以项目更改:
项目右键 -》properties -》Java Build Path -》source -》Default output folder,选择你的路径,ok!

 

评论 36
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值