Struts 2 – HTTP状态404 – 没有为操作定义结果
我正在尝试开发一个Struts2应用程序,其中在单击超链接时调用操作,该超链接使用Struts动作映射将用户指向hello.jsp。 我收到以下错误:
HTTP Status 404 - No result defined for action com.manaar.action.HelloAction and result success
我的文件如下。 我的映射看起来像是按顺序。 我还在这里检查了其他post,但似乎无法找到这个问题的原因或解决方案。 非常感谢任何建议。 非常感谢,J
index.jsp
:
Struts 2 Actions
Welcome ! | Logout |
Hello Action Add User View Users Login
struts.xml
:
/hello.jsp
HelloAction.java
:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.manaar.action; import com.opensymphony.xwork2.Action; import static com.opensymphony.xwork2.Action.SUCCESS; public class HelloAction implements Action { String message; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } /** * * @return * @throws Exception */ @Override public String execute() throws Exception { setMessage("Hello From Struts!"); return SUCCESS; } }
您可以使用配置浏览器插件 。 如果要查看浏览器中的配置以及操作如何映射到URL,这将非常有用。
实际上,您使用约定插件的问题的原因。 如果将struts2-convention-plugin-2.3.x.jar
放入WEB-INF/lib
。 安装后,它会扫描struts-plugin.xml
定义的包,并按约定创建一个额外的struts.xml
配置。 除了您的操作符合插件使用的规则之外,还为类HelloAction
创建了"hello"
操作,但遗憾的是它没有"success"
的结果。 要将此结果添加到操作中,您应该在类上使用@Result
注释,或使用@ResultPath
注释指定结果的路径,而不是默认的WEB-INF/content
。 如果应用struts.convention.result.path
配置设置,则可以执行相同的操作。
@Result(name = SUCCESS, location = "/hello.jsp")
另请注意,您在struts.xml
为动作"hello"
定义的映射具有较少的含义,除非它映射到指定的方法。 JSP的名称应该是index.jsp
的拼写错误。
我想你错过了在HelloAction中编写方法“wateva”。 因此,要么将其写入代替执行,要么将其从struts映射中删除。
/hello.jsp