There is no Action mapped for namespace / and action name login等Strut2错误总结!!
(2011-11-04 14:25:07)
There is no Act ion mapped fornamespace / and act ion namelogin
这个错误找的哥,好累!
总算揪出来是哪里捣的鬼了。
主要原因:
1.配置文件名为struts.xml不是,my eclipse自动生成的,struts-config。
2.这个配置文件还放错了位置。放在类路径下,不长眼的我,居然放错了!
下面是一些转载的参考文件:
首先说明一下示例的文档结构:
|----LoginAction.java
//act
ion类
|------META-INF
|------WEB-INF
|----lib
|----web.xml
|-----error.html
|-----index.jsp
|-----success.html
LoginAction.java:
/
imp
ort com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
private String username ;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute () throws Exception
{
if(getUsername().equals("root")&&this.getPassword().equals("root")){
return "success";
}
else
{
return
"error";
}
}
}
//
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name ="strut2" extends ="struts-default"
namespace="/strut" >
<act
ion name ="login" class="cn.balance.LoginAction">
<result name ="error">/error.html</result>
</act
ion>
</package>
</struts>
///
web.xml ---->本例为Myeclipse8.0GA创建,与手动创建的<filter-class>有所不同:
请视具体strut2的版本,情况而定(两个都一样)
/
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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_2_5.xsd">
error.html
//
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
</html>
//
success.html
///
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
</html>
//
index.jsp
<%@ page language="java" imp
ort="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
out.print(basePath);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</html>
↑ 好了以上就是程序的全部代码 ↑ 下面说一下常见得错误:
错误:
There is no Act ion mapped for namespace / and act ionname login
首先出现这种错误是因为配置文件没找到,检查一下你的struts.xml是否在classes 文件夹下
路径:“安装Tomcat 的路径”\webapps\“你工程的名称”\WEB-INF\classes
其次,查看你的struts.xml这个文件名称是否与“struts.xml”一样,并且检查其中内容是否正确,每一个属性都要检查
注意拼写错误!!!!!!
再次,如果没用<s:form>的话形式应该是这样:<form
act
ion="strut/login.act
ion" >
如果你用的是<s:form >形式那应该是:<s:form name ="form1" act
ion ="login" namespace="/strut">
↓↓↓要记住↓↓↓
form 标签 没有namespace属性
form 标签
s:form 标签
有namespace属性
………………………………↑曾经因为这个蛋疼两天
运行起来 成功就出现 :
success!Congratulations!!
用户名或密码错误出现:(本例用户名密码都是root)
Name or Password error!But
Your demo still sucess!!! Congratulations!
好了,看看你的程序运行起来没::::::