Java Struts 2找不到从操作返回的成功结果
我不是以英语为母语的人,所以如果我犯了一些惯用的错误,我深表歉意。我对Struts2一无所知。 我开发了一个web项目,其中包含3个JSP页面、一个部署描述符(web.xml)、一个struts配置文件(struts.xml),其中配置了2个操作(一个名为index的操作和一个名为welcome的操作),以及一个实现欢迎操作的操作逻辑的类。当我尝试索引操作时,它工作得非常好,但是如果我在URL中调用欢迎操作(welcome.action),我会得到以下错误Java Struts 2找不到从操作返回的成功结果,java,macos,jsp,netbeans,struts2,Java,Macos,Jsp,Netbeans,Struts2,我不是以英语为母语的人,所以如果我犯了一些惯用的错误,我深表歉意。我对Struts2一无所知。 我开发了一个web项目,其中包含3个JSP页面、一个部署描述符(web.xml)、一个struts配置文件(struts.xml),其中配置了2个操作(一个名为index的操作和一个名为welcome的操作),以及一个实现欢迎操作的操作逻辑的类。当我尝试索引操作时,它工作得非常好,但是如果我在URL中调用欢迎操作(welcome.action),我会得到以下错误 Struts Problem Repo
Struts Problem Report
Struts has detected an unhandled exception:
Messages:
No result defined for action actions.WelcomeAction and result success
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)
...
现在,我向您介绍有关项目和环境的更多信息:
开发环境
- 操作系统:Mac OS X 10.10.3
- JRE:1.8.0_20
- IDE:NetBeans 7.4
- 应用服务器:GlassFish 4.0
- 服务器位置:localhost:8080
- 上下文路径:/AppStruts2Example
- URL项目:
- JavaEE版本:7
- Struts2版本:2.3.15
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.configuration.xml.reload" value="true" />
<!-- Configuration for the default package. -->
<package name="default" extends="struts-default">
<action name="index">
<result>/WelcomeFromIndexAction.jsp</result>
</action>
<action name="welcome" class="actions.WelcomeAction">
<result name="success">/WelcomeFromWelcomeAction.jsp</result>
</action>
</package>
</struts>
index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index JSP</title>
</head>
<body>
<h1>Welcome to index.jsp!</h1>
</body>
</html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index Action</title>
</head>
<body>
<h1>Welcome From Index Action</h1>
<br />
<h3>Current Page: WelcomeFromIndexAction.jsp</h3>
</body>
</html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome Action</title>
</head>
<body>
<h1>Welcome From Welcome Action</h1>
<br />
<h3>Current Page: WelcomeFromWelcomeAction.jsp</h3>
</body>
</html>
索引JSP
欢迎使用index.jsp!
欢迎来自IndexAction.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index JSP</title>
</head>
<body>
<h1>Welcome to index.jsp!</h1>
</body>
</html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index Action</title>
</head>
<body>
<h1>Welcome From Index Action</h1>
<br />
<h3>Current Page: WelcomeFromIndexAction.jsp</h3>
</body>
</html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome Action</title>
</head>
<body>
<h1>Welcome From Welcome Action</h1>
<br />
<h3>Current Page: WelcomeFromWelcomeAction.jsp</h3>
</body>
</html>
指数作用
欢迎来自Index Action
当前页面:WelcomeFromIndexAction.jsp
WelcomeFromWelcomeAction.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index JSP</title>
</head>
<body>
<h1>Welcome to index.jsp!</h1>
</body>
</html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Index Action</title>
</head>
<body>
<h1>Welcome From Index Action</h1>
<br />
<h3>Current Page: WelcomeFromIndexAction.jsp</h3>
</body>
</html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome Action</title>
</head>
<body>
<h1>Welcome From Welcome Action</h1>
<br />
<h3>Current Page: WelcomeFromWelcomeAction.jsp</h3>
</body>
</html>
欢迎行动
欢迎来自欢迎行动
当前页面:WelcomeFromWelcomeAction.jsp
在以下情况下,项目工作正常:
- 我直接在浏览器上写入任何JSP的URL
- 我调用index操作,如下所示:/index.action或/index->将我重定向到WelcomeFromIndexAction.jsp
- 我调用欢迎操作,如下所示:/welcome.action或/welcome->这两个选项都显示了一个包含Struts问题报告的网页,如上所述
谢谢 在struts.xml中使用名为editUser的action类中的自定义方法创建条目,以便控制直接转到该perticular方法,并相应地处理逻辑中的结果
<action method="editUser" name="editUser" class="com.action.EditUserAction">
<result name="true">/jsp/editUser.jsp</result>
<result name="false">jsp/index.jsp</result>
</action>
如果问题仍然存在,则执行相同操作后,请仔细检查配置解决此问题的最佳方法是使用Maven创建项目并管理可能需要的所有依赖项。这是唯一对我有效的解决办法 下面是使用Maven创建Struts 2 Web应用程序的官方指南(非常简单的示例): 如果您尚未安装Maven is OS X,并且不知道如何安装,请按照以下步骤安装: 下载Maven(本例使用Maven 3.3.3。压缩文件的名称为apache-Maven-3.3.3-bin.tar.gz): 解压缩下载的文件(本例假设下载的文件位于/Users/YourUser/Downloads/)。解包后,将创建一个与下载的maven文件具有相同名称和路径的新目录。(在本例中:/Users/YourUser/Downloads/apache-maven-3.3.3/) 打开终端 使用以下命令将maven目录移动到主目录: mv~/Downloads/apache-maven-3.3.3/~/ 现在,您必须编辑位于主目录(~/.bash\u profile)上的文件.bash\u profile。要编辑它,我们将使用vi commando,如下所示: vi~/.bash_简介 打开后,必须按i键进行编辑 现在您可以编辑该文件,因此必须编写以下内容: 导出JAVA_HOME=$(/usr/libexec/JAVA_HOME) export-MAVEN=$HOME/apache-MAVEN-3.3.3/bin 关闭终端并再次打开。就这些,Maven应该已经安装好了。使用以下命令验证Maven是否正常工作: mvn-版本
如果您看到有关Maven、Java和OS X的信息,那是因为Maven工作正常。您的配置看起来不错。。可能您有一个旧的struts.xml文件正在部署请使用maven重新创建您的项目,因为您可能有错误的依赖项使用配置浏览器插件它将帮助您找到mapping@EliseoCastro要回答自己的问题,只需添加答案,而不是编辑问题;)