我正在使用Struts2。我有两个具有相同代码的 Web 表单。我想消除一种形式。这是我的 Struts 项目的结构。
\Web Pages
form.jsp
\WEB-INF
\Content
error.jsp
form.jsp
success.jsp
\Source Packages
\action
MyAction.java
MyAction.java
package action;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.*;
public class MyAction extends ActionSupport {
@Action(value = "foo", results = {
@Result(name = "input", location = "form.jsp"),
@Result(name = "success", location = "success.jsp"),
@Result(name = "error", location = "error.jsp")
})
public String execute() throws Exception {
if (user.length() == 1) {
return "success";
} else {
return "error";
}
}
private String user = "";
public void validate() {
if (user.length() == 0) {
addFieldError("user", getText("user required"));
}
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
}
我试图通过向 MyAction.java 添加一个新的操作方法来消除 \Web Pages 下的 form.jsp。
@Action(value="bar", results = {
@Result(name = "success", location = "form.jsp"),
})
public String another() {
return "success";
}
但是当我转到 http 时出现以下错误://localhost .../bar.action
HTTP 状态 404 - 未为操作 action.MyAction 和结果输入定义结果