Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Struts 2找不到从操作返回的成功结果_Java_Macos_Jsp_Netbeans_Struts2 - Fatal编程技术网

Java Struts 2找不到从操作返回的成功结果

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

我不是以英语为母语的人,所以如果我犯了一些惯用的错误,我深表歉意。我对Struts2一无所知。 我开发了一个web项目,其中包含3个JSP页面、一个部署描述符(web.xml)、一个struts配置文件(struts.xml),其中配置了2个操作(一个名为index的操作和一个名为welcome的操作),以及一个实现欢迎操作的操作逻辑的类。当我尝试索引操作时,它工作得非常好,但是如果我在URL中调用欢迎操作(welcome.action),我会得到以下错误

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项目:
Web项目开发信息

  • JavaEE版本:7
  • Struts2版本:2.3.15
代码描述如下

web.xml

<?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问题报告的网页,如上所述
我认为这可能是GlassFish服务器的问题,所以我在VM上安装了Debian,并在那里安装了Tomcat7。我的下一步是使用NetBeans的“清理和构建”部署web应用程序。它生成了一个WAR文件,我将其部署到Tomcat7中,但我遇到了同样的问题。在这令人失望之后,我禁用了Debian VM(Tomcat 7),然后重新使用GlassFish 4.0

正如您在WelcomeAction.java中看到的,它在execute方法中有一个println语句。当我在浏览器上调用welcome action时,我可以看到Struts有效地调用了该方法,行被打印在输出上,在调用之后,Struts2必须处理结果,然后向我显示错误。这证实了Struts2没有找到结果,也没有找到行动,但我不知道为什么

我尝试使用旧版本和新版本的过滤器(FilterDispatcher/StrutsPrepareAndExecuteFilter)配置过滤器调度器。这两个问题我都有。 我尝试在struts.xml中配置与索引操作完全相同的欢迎操作(实际上在默认情况下),但不起作用。只有索引操作才能正常运行。 我尝试用多种方式在struts.xml中配置欢迎操作,但没有任何效果

所以,我在这里,需要有人帮助我。我感谢你的回答

注意:Stackoverflow不允许我发布图像,因为我是新手。因此,我上传了一个重要的打印屏幕到我的dropbox。 在这个打印屏幕上,您可以看到添加的库、execute方法的执行、定制的打印行和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要回答自己的问题,只需添加答案,而不是编辑问题;)