我試圖開發一個Struts2應用程序,在單擊超鏈接時使用Struts動作映射將用戶引導到hello.jsp時調用動作。我收到以下錯誤:Struts 2 - HTTP狀態404 - 沒有爲行動定義的結果
HTTP Status 404 - No result defined for action com.manaar.action.HelloAction and result success
我的文件如下。我的映射看起來像它的順序。我也在這裏檢查了其他帖子,但似乎無法找到導致此問題的原因或解決方案。真的很感激任何建議。非常感謝,J
index.jsp
:
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<title><s:text name="app.title" /></title>
<link rel="stylesheet" href="mystyle.css" type="text/css" />
</head>
<body>
<center>
<h2>
Struts 2 Actions
</h2>
<br>
<br>
Welcome
<s:property value="#session.user" default="Guest" />!
<s:if test="#session.user!=null">
<s:url id="logout" action="logout" />
| <s:a href="%{logout}">Logout</s:a> |
</s:if>
<br>
<table cellspacing="5" width="180">
<tr bgcolor="#f0edd9" height="25" align="center">
<td>
<s:url id="hello" action="hello"/>
<s:a href="%{hello}">Hello Action</s:a>
</td>
</tr>
<tr bgcolor="#f0edd9" height="25" align="center">
<td>
<s:a href="add_user.jsp">Add User</s:a>
</td>
</tr>
<tr bgcolor="#f0edd9" height="25" align="center">
<td>
<s:a href="user.jsp">View Users</s:a>
</td>
</tr>
<tr bgcolor="#f0edd9" height="25" align="center">
<td>
<s:a href="login.jsp">Login</s:a>
</td>
</tr>
</table>
</center>
</body>
</html>
struts.xml
:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- Configuration for the default package. -->
<package name="default" extends="struts-default">
<action name="hello" class="com.manaar.action.HelloAction" method="wateva">
<result name="success">/hello.jsp</result>
</action>
</package>
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;
}
}
嘗試在HelloAction中創建一個方法wateva,並從該方法返回SUCCESS,或者您可以在struts.xml中調用execute方法而不是whateva –
我嘗試徹底刪除方法wateva,並且得到相同的錯誤。然後我嘗試從struts.xml調用execute。同樣的錯誤 –