我跟着风中叶视频的第一个Struts2应用做,但是未成功。
现象:
login.jsp页面能被正常请求到,但是点击submit之后就不行了。页面错误信息:
HTTP Status 404 - There is no Action mapped for namespace / and action name login.
type Status report
message 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.控制台错误信息:
2008-6-13 18:39:08 org.apache.struts2.dispatcher.Dispatcher serviceAction
严重: Could not find action or result
There is no Action mapped for namespace / and action name login. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
………………环境:
          apache-tomcat-6.0.16
          jdk   1.5
          struts-2.0.11
          myeclipse  6.0 (eclipse  3.3.2)包:
五个包。没有用更多的。Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Struts 2.0 Hello World</display-name>
<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>login.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=UTF-8">
<title>This is "login.jsp" page</title>
</head>
<body>
<form action="login.action" method="post">
username:
<input type="text" name="username">
<br>
password:
<input type="password" name="password">
<br>
<input type="submit" value="submit">
</form>
</body>
</html>struts.xml(在src下面,编辑之后自动拷贝到classes文件夹下面了):
<?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="default" extends="struts-default"> <action name="login" class="com.ecc.struts2.action.LoginAction">
<result name="success">/result.jsp</result>
</action> </package></struts>result.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
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=UTF-8">
<title>This is "result.jsp" Page.</title>
</head>
<body>
username:${ requestScope.username }
<br>
password:${ requestScope.password }
<br>
</body>
</html>
请问各位大侠,该如何解决?在此感谢!

解决方案 »

  1.   

    com.ecc.struts2.action.LoginAction这个类贴出来
      

  2.   

    估计是你的action没有继承至actionsupport这个类
        ActionSupport类在com.opensymphony.xwork2.ActionSupport中。
      

  3.   

    继承不继承无所谓的,只要返回的字符串与struts.xml中result的name一致就行,如你访问login.action,那么在struts.xml中应该有一个name为login的action与其对应,在name为login的action对应的类中应该有一个名称叫execute的方法,如果访问login!test.action,则在对应的类中应该有一个名称叫test的方法,不管是execute还是test方法,返回值必须是一个字符串,这个字符串必须与struts.xml中配置的action的其中一个result的name一致或者是全局转发的result的name一致。如果在struts.xml中找不到对应的action或action类中执行方法的返回字符串在struts.xml中找不到对应的result,就会出现楼主的错误
      

  4.   

    不是的,要继承ActionSupport类,好象不继承就会出错来着;我们开发过三个这样的项目!!!什么struts2的文件上传等等,差不多基本的都用到了..........................
      

  5.   

    HTTP Status 404 - There is no Action mapped for namespace / and action name login. 是没找到映射,无非是映射的路径或者或者映射名字写错了login. 说明你的链接是以action为后缀的,检查检查路径吧
      

  6.   

    如果你继承了ActionSupport,那么配置struts.xml中:
    <action name="login" class="com.ecc.struts2.action.LoginAction"> 
      <result name="success">/result.jsp </result> 
    </action>
    象你这样写就可以了,。
    如果你没有继承ActionSupport,那么在struts.xml中必须这样写:
    <action name="login.action" class="com.ecc.struts2.action.LoginAction"> 
      <result name="success">/result.jsp </result> 
    </action> 
     
      

  7.   

    我最近也在初学Struts2.0,也是看风中叶的视频,出现了同样的问题!我是按照
    <action name="login.action" class="com.ecc.struts2.action.LoginAction"> 
      <result name="success">/result.jsp </result> 
    </action>
    这样写的,似乎仍然出现楼主说的相同的错误,到底是哪里出错了呢?
      

  8.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【cwxinxiang】截止到2008-07-18 13:36:46的历史汇总数据(不包括此帖):
    发帖的总数量:1                        发帖的总分数:20                       每贴平均分数:20                       
    回帖的总数量:2                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:1                        结贴的总分数:20                       
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:100.00%               结分的百分比:100.00%                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    敬礼!
      

  9.   

    配置没有什么问题啊?
    是不是struts。xml 文件位置放的不对呢?
    web-info/classes下吗?
      

  10.   

    是不是和这个一样?http://hi.baidu.com/huqiwen/blog/item/9f1027978656b26855fb9688.html/cmtid/04ad6438992e9e2496ddd84a#04ad6438992e9e2496ddd84a
      

  11.   

    我也碰到了,应该是struts.xml配置有问题
    <struts>
    <packagte name="struts2" namespace="/" extends="struts-default">
    <action>...
    </action>
    </package>
    </struts>不要漏了namespace="/"这个配置
      

  12.   

    在struts.xml所在目录下建一个文件struts.properties.文件里面的内容写struts.locale=en_GB。看这样能不能行
    你的struts.xml里的<package name="default" extends="struts-default"> 跟教程里的不一样。
      

  13.   

    <filter-mapping> 
    <filter-name>struts2 </filter-name> 
    <url-pattern>/* </url-pattern> 
    </filter-mapping>
    这样一来,jsp页面应该访问不到啊
      

  14.   

    是不是那个namespace中配置错了啊
      

  15.   

    com.ecc.struts2.action.LoginAction类应该没问题  你是404错误  404是页面跳转出错 能让页面跳转出错的字有表单的action 和struts.xml   
    一个struts2引来这么多人关注  这说明会struts2的人太多了   
      

  16.   

    <action name="login.action" class="com.ecc.struts2.action.LoginAction" mothed="把你的action里的登录方法名加上">  
      

  17.   

    在你的struts的配置文件中的<action>节点中加上namespace="/"
      

  18.   

    在struts.xml文件中配置的时候,加上namespace:
    <package name="default" extends="struts-default" namespace="/">
      

  19.   

    web.xml加上<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    还有,你的action代码呢?
      

  20.   

      不用action怎么玩转struts呢。
      

  21.   

    login.action 改个名字 不要用login