错误提示:HTTP Status 404 - There is no Action mapped for namespace / and action name login.
type Status reportmessage There is no Action mapped for namespace / and action name login.description The requested resource (There is no Action mapped for namespace / and action name login.) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.20下面上代码:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>re</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
struts.xml<?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>
     <package name="example" namespace="example" extends="struts-default">
     <action name="login" class="com.re.example.loginAction">
     <result name="success">/success.jsp</result>
     <result name="fail">/fail.jsp</result>
     </action>
     </package>
    </struts>loginAction.javapackage example;
public class loginAction {
private String usename;
private String password;
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setUsename(String usename) {
this.usename = usename;
}
public String getUsename() {
return usename;
}
public String execute() throws Exception{
if(getUsename().equals("admin")&&getPassword().equals("pass")){
return "success";
}
else{
return "fail";
}
}
}index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>登陆页面</title>
</head>
<body>
<form action="login" method="post">
用户:<input type="text" name="usename"/><br/>
密码:<input type="password" name="password"/><br/>
<input type="reset" value="重置"><input type="submit" value="提交"/>
</form>
</body>
</html>

解决方案 »

  1.   

    <package name="example" namespace="/" extends="struts-default">
    试试
      

  2.   

    <package name="example" namespace="/" extends="struts-default"> 
      

  3.   

    There is no Action mapped for namespace / and action name login.路径错误了
    <action name="login" class="com.re.example.loginAction">里面的path呢好久没用过Action了 不知道说的是否正确  
      

  4.   

    这是一个关于如何理解struts 2的namespace的问题:看了一下可以注意两个地方:1. 要将<package name="example" namespace="example" extends="struts-default">
       改成:<package name="example" namespace="/example" extends="struts-default">2. 在浏览器输入url的时候要用:http://xxxx/example/login.action
      

  5.   

    还有就是要把: <form action="login" method="post">
     改成:  <form action="login" namespace='/example' method="post">
      

  6.   

    试下加上应用名:
    "/<App_Name>/login"
      

  7.   

    我都傻子,不知道怎么回事了。
    就照着Tomcat下面的例子写的都不行。
    真是郁闷了。
      

  8.   

    好像知道是怎么回事了:楼主要用struts 2的标签呀:
    <form action="login" method="post">
    改成:
    <s:form action="login" namespace='/example' method="post"> 等等...
      

  9.   

    好经典的错误啊.我的 namespace=""
      

  10.   

    试试
    <form action="example/login" method="post">
    namespace问题,要加入url的
      

  11.   

    按楼上的改了。
    现在是
    HTTP Status 404 - There is no Action mapped for action name login.
    错误了。
      

  12.   

    我昏啊,哈哈哈哈。
    Struts.xml写成了sturts.xml
    彻底无语了