Java 行动总是成功的回报

Java 行动总是成功的回报,java,jsp,struts2,Java,Jsp,Struts2,我是STRUTS2的初学者,我想测试两个动作 第一个操作产品工作正常。当我输入“hello”时返回成功,否则返回错误 但是第二个动作catererType总是成功的 谁能解释一下原因吗 下面是Product.java package com.javatpoint; import com.opensymphony.xwork2.ActionSupport; public class Product extends ActionSupport { private int id; private

我是STRUTS2的初学者,我想测试两个动作

第一个操作
产品
工作正常。当我输入“hello”时返回成功,否则返回错误

但是第二个动作
catererType
总是成功的

谁能解释一下原因吗

下面是Product.java

package com.javatpoint;

import com.opensymphony.xwork2.ActionSupport;

public class Product extends ActionSupport {
private int id;
private String name;
private float price;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public float getPrice() {
    return price;
}

public void setPrice(float price) {
    this.price = price;
}

public String execute() {
    if(name.equals("hallo")){

        return SUCCESS;
    }
    else{
    return ERROR;
    }
}
}
CatererType.java

package com.javatpoint;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.opensymphony.xwork2.ActionSupport;

public class CatererType extends ActionSupport {

private String description;

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

public String excute() {

    if (description.equals("hello")) {

        return ERROR;
    } else {
        return SUCCESS;
    }

}
}
accessdiened.jsp

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Access Denied</title>
</head>
<body>
You are not authorized to view this page.
</body>
</html>

拒绝访问
您无权查看此页面。
welcome.jsp

<%@ taglib uri="/struts-tags" prefix="s" %>  
The Caterer Type: <s:property value="description"/> was inserted <br/>  

餐饮服务商类型:已插入
adminpage.jsp

<%@ taglib uri="/struts-tags" prefix="s" %> 
<html> 
<center>
<s:form action="caterertype">  
<s:textfield name="description" label="Caterer Type"></s:textfield>  
<s:submit value="save"></s:submit>  
</s:form>  
</center>
</html>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts  
Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">  
<struts>  
<constant name="struts.devMode" value="false" />

<constant name="struts.custom.i18n.resources" value="ApplicationResources"  />
<package name="default" extends="struts-default">  

<action name="product" class="com.javatpoint.Product" method="execute">  
<result name="success">welcome.jsp</result>  
<result name="error">/AccessDenied.jsp</result>
</action>  
<action name="caterertype" class="com.javatpoint.CatererType" method="execute"> 
<result name="success">welcome.jsp</result> 
<result name="error">AccessDenied.jsp</result>
</action>

</package>  
</struts>  

welcome.jsp
/AccessDenied.jsp
welcome.jsp
AccessDenied.jsp

如果这是问题所在,我注意到搜索时存在一些差异:/AccessDenied.jsp带反斜杠welcome.jsp AccessDenied.jsp不带反斜杠,在操作中一个人写了hello other halloi删除了两者中的反斜杠,并在两者中都添加了反斜杠,但在CatererType中仍然返回始终成功对不起,你能像在Product中一样在CatererType中编写方法excute()吗?我做了,但excute仍然始终返回成功我不确定,但你可以在action类的input中修剪()字符串