刚学struts2,刚写了个用struts2框架实现的程序,一直报如下错误HTTP Status 404 - No result defined for action com.test.action.LoginAction and result success--------------------------------------------------------------------------------type Status reportmessage No result defined for action com.test.action.LoginAction and result successdescription The requested resource (No result defined for action com.test.action.LoginAction and result success) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.33
struts.xml文件(位于src目录下)如下:<?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="struts2" extends="struts-default">
<action name="login" class="com.test.action.LoginAction">
<result name="success">/hello.jsp</result>
</action>

</package></struts>web.xml文件(位于WEB-INF目录下)如下:
<?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>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <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></web-app>

解决方案 »

  1.   

    Action类如下:package com.test.action;
    /**
     * 
     *//**
     * @author windson
     *
     */
    public class LoginAction { private String name;
    private String password;
    /**
     * @return the name
     */
    public String getName() {
    return name;
    }
    /**
     * @param name the name to set
     */
    public void setName(String name) {
    this.name = name;
    }
    /**
     * @return the password
     */
    public String getPassword() {
    return password;
    }
    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
    this.password = password;
    }

    public String execute() throws Exception{

    System.out.println("hahahhahah");
    System.out.println("hahahhahah");
    System.out.println("hahahhahah");
    System.out.println("hahahhahah");
    System.out.println("hahahhahah");
    String str = new String("success");
    return str; 


    }



    }
      

  2.   

    调试过程中,tomcat6.0的命令行提示框里面execute是执行了的,所以估计是struts.xml文件出了问题,但是怎么也找不出
      

  3.   

    如果能进execute应该不是struts.xml return str 改为return SUCCESS;
      

  4.   

    直接换
    return "SUCCESS"或return "success"试试
      

  5.   

    进入了action证明<action name="login" class="com.test.action.LoginAction">没问题而且result的name也没错
    <result name="success">/hello.jsp</result>
    哦,应该是hello.jsp路径不对了,检查一下.
      

  6.   

    你这个action类继承一下actionsupport类。
    然后直接return SUCCESS   大写 没引号。
      

  7.   

    +1
    调试没问题,那估计就是jsp的路径错了,你把namespace加上看看
      

  8.   

    太谢谢了,是namespace的问题,加了namespace="/"就好了
    能给我解释下吗
      

  9.   

    404路径错误咯:
    message No result defined for action com.test.action.LoginAction and result success这里的 result successaction中 return SUCCESS配置文件:<result name="success">/页面.jsp</result>试试看............
      

  10.   

    你的action里面的return str  要改成  你的struts配置文件里面的result下的name同名
      

  11.   

    执行execute()方法 返回的是str  struts2配置文件里面的result name应该是 str 不应该是success
      

  12.   

    return str---->return "success"
      

  13.   

     很明显:
    <filter-name>struts2</filter-name>
          <filter-class>
              org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
          </filter-class>改成
    <filter>
            <filter-name>struts-cleanup</filter-name>
            <filter-class>
                org.apache.struts2.dispatcher.ActionContextCleanUp
            </filter-class>
        </filter>
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>

    <filter-mapping>
    <filter-name>struts-cleanup</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>还有,最后返回的时候 
     <package name="struts2" extends="struts-default">
            <action name="login" class="com.test.action.LoginAction">
               <result name="success">/hello.jsp</result>
    </action>
    name = "success"多此一举了不需要。。默认就是success,action中return SUCCESS就行了。。
      

  14.   

    如果实在要用 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    ,必须确保你的struts2版本至少在 2.1.6、2.1.8吧