org.apache.struts2.dispatcher.dispatcher:找不到操作或结果错误

org.apache.struts2.dispatcher.dispatcher:找不到操作或结果错误,struts2,Struts2,我试图编写以下简单的struts,但在运行时遇到了这个错误 [org.apache.struts2.dispatcher.Dispatcher] Could not find action or result: No result defined for action com.peter.action.LoginAction and result success index.jsp <%@ page language="java" contentType="text/html; c

我试图编写以下简单的struts,但在运行时遇到了这个错误

[org.apache.struts2.dispatcher.Dispatcher] Could not find action or result: 
No result defined for action com.peter.action.LoginAction and result success  
index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"  
    pageEncoding="ISO-8859-1"%>  
<%@ taglib prefix="s" uri="/struts-tags" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
  <body>  
    <h2>Hello Struts</h2>  

    <s:form action="login" >  
      <s:textfield name="username" label="Username:" />  
      <s:password name="password" label="Password:"/>  
      <s:submit />  
    </s:form>  
  </body>  
</html>
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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>Struts</display-name>

    <filter>
        <filter-name>Struts_Filter</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        <init-param>
            <param-name>actionPackages</param-name>
            <param-value>com.peter.action</param-value> 
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>Struts_Filter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>    
除了运行时错误外,还有部署错误

错误[com.opensymphony.xwork2.util.finder.ClassFinder]MSC服务 线程1-2无法读取类 [WEB-INF.classes.com.peter.action.LoginAction]:无法加载 WEB-INF/classes/com/peter/action/LoginAction.class-[未知 位置]在 com.opensymphony.xwork2.util.finder.ClassFinder.readClassDefClassFinder.java:785 [xwork-core-2.3.1.2.jar:2.3.1.2]


好的,struts的扫描方法将扫描名为struts2的默认包中任何带注释的类,但我已经指示struts2使用init param在com.peter.action中扫描,但仍然找不到该类。这很奇怪

我通过更改为xml映射样式解决了这个问题

升级到Struts 2.3.8时,我遇到了同样的问题,除了错误的类包以WEB-INF开头之外。*它以WAR文件名开头。我通过在struts.xml中添加以下行解决了这个问题:


除了WarFileName.*之外的所有内容都是默认值,所以我也包括了这些内容。我希望这对某些人有所帮助。

它说它无法读取类。它部署了吗?当然,检查是否有类。将来添加struts2 config browser jar,然后转到/config browser/index,看看它告诉您什么。另外,只有当struts2 conventions插件存在时,您关于包扫描的声明才适用。我认为它应该用于大多数项目,个人来说是所有项目。LoginAction.class位于jboss部署文件夹中。struts2配置浏览器的用途是什么。我已经将struts2约定插件包含到类路径中。任何人都可以提供帮助。您是如何更改xml映射样式的?解释?你是怎么改变的?请你解释一下,好让其他人得到一些解决办法。。没有任何解释,你的答案是没有用的。谢谢
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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>Struts</display-name>

    <filter>
        <filter-name>Struts_Filter</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        <init-param>
            <param-name>actionPackages</param-name>
            <param-value>com.peter.action</param-value> 
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>Struts_Filter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>    
<constant name="struts.convention.exclude.packages" value="org.apache.struts.*,org.apache.struts2.*,org.springframework.web.struts.*,org.springframework.web.struts2.*,org.hibernate.*,WarFileName.*"/>