Eclipse中配置Struts2出现There is no Action mapped for action name loginAction. - [unknown location]

eclipse中配置struts2时报:
          Eclipse中配置Struts2出现There is no Action mapped for action name loginAction. - [unknown location]
          错误
做如下检查:
1、确保struts.xml文件名大小写正确:struts.xml(全部小写,我就是这里出错了)
2、确保struts.xml文件在src目录下(很重要!后面就着重说这个)
附:
     web.xml
1 <? xml version= "1.0" encoding= "UTF-8" ?>
2
< 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"> 3 < display-name >Struts </display-name > 4 5 6 < filter> 7 <filter-name >struts2 </filter-name > 8 <filter-class >org.apache.struts2.dispatcher.FilterDispatcher </filter-class > 9 </ filter> 10 < filter-mapping > 11 <filter-name >struts2 </filter-name > 12 <url-pattern >/* </url-pattern > 13 </ filter-mapping > 14 15 < welcome-file-list > 16 <welcome-file >login.jsp </welcome-file > 17 18 </ welcome-file-list > 19 </ web-app>

 struts.xml

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 4     "http://struts.apache.org/dtds/struts-2.3.dtd">
 5 <struts>
 6     <package name="default" namespace="/" extends="struts-default">
 7         <action name="LoginAction" class="com.lizanhong.action.LoginAction">
 8             <!-- 定义逻辑视图和物理资源之间的映射 -->
 9             <result name="error">index.jsp</result>
10             <result >/WEB-INF/main.jsp</result>
11         </action>
12     </package>
13 </struts>

index.jsp

 1  <%@ page language="java" contentType="text/html; charset=GB18030"
 2     pageEncoding="GB18030"%>
 3     <%@ taglib prefix="s" uri="/struts-tags" %>
 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 5 <html>
 6 <head>
 7 <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
 8 <title>Struts2登录界面</title>
 9 </head>
10 <body>
11  <s:form action="LoginAction" namespace="/">
12  <tr>  
13 <td colspan="2" align="center">  Login  </td>  
14  </tr>  
15  <tr>  
16    <td colspan="2">  
17          <s:actionerror />  
18          <s:fielderror />  
19    </td>  
20   </tr>  
21      <s:password name="name" label="用户名"></s:password>
22       <s:textfield name="password" label="密码"></s:textfield>
23       <s:submit  name="submit"  value="确定" ></s:submit> 
24 </s:form>
25 </body>
26 </html>

 

错误总结:

1.   struts.xml中的 <action>标签name="LoginAction"要与 index.jsp中 <form>标签action="LoginAction" 一致;

2.   struts.xml中的 <package>标签namespace="/"要与 index.jsp中 <form>标签namespace="/" 一致;

3.   配置好后若有修改重启一下服务器;

 

 

posted @ 2014-03-16 17:29  estella  阅读(6458)  评论(3编辑  收藏  举报