没有为操作和结果定义结果

No Result Defined for action and result

我想验证 jsp 页面中的文本字段。我正在使用 struts。我的验证函数抛出如下所述的错误。

HTTP Status 404 - No result defined for action SIS.Student.AddUser and result input

这些是我的表单参数。

<s:form id="FormAddUser" name="FormAddUser" action="AddUser" method="post"
    enctype="multipart/form-data" class="form-horizontal">
    <s:textfield key="UserId" label="UserId" />
    <s:textfield key="Name" label="Name" />
    <s:textfield key="Address" label="Address" />
    <s:textfield key="DOB" label="DOB" />
    <s:password key="Password" label="Password" />
    <s:textfield id="EmailId" key="EmailId" label="EmailId" />
    <s:textfield id="Specialization" key="Specialization" label="Specialization" />
    <s:file name="UserImage" id="UserImage" key="UserImage" label="Select a File to change photo" />
    <s:submit label="Add" />
</s:form>

这是我的操作中的验证函数 class:

public class AddUser extends ActionSupport implements ServletRequestAware 
{

    public void validate()
   {
     if (StringUtils.isEmpty(UserId)) {addFieldError("UserId", "UserId cannot be blank");}
     if (StringUtils.isEmpty(Name)) {addFieldError("Name", "UserId cannot be blank");}
     if (StringUtils.isEmpty(Address)) {addFieldError("Address", "UserId cannot be blank");}
     if (StringUtils.isEmpty(DOB)) {addFieldError("DOB", "UserId cannot be blank");}
     if (StringUtils.isEmpty(Password)) {addFieldError("Password", "UserId cannot be blank");}
     if (StringUtils.isEmpty(EmailId)) {addFieldError("EmailId", "UserId cannot be blank");}
     if (StringUtils.isEmpty(Specialization)) {addFieldError("Specialization", "UserId cannot be blank");}
   }

这是我的struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="studentInfo" extends="struts-default" namespace="/">
    <action name="AddUser" class="SIS.Student.AddUser"      method="execute">
        <interceptor-ref name="fileUpload">
            <param name="maximumSize">2097152</param>
            <param name="allowedTypes">
                image/png,image/gif,image/jpeg,image/pjpeg
            </param>
        </interceptor-ref>
        <interceptor-ref name="defaultStack"></interceptor-ref>

        <result name="success">/Index.jsp</result>
        <result name="error">/Index.jsp</result>
        <result name="input">/Index.jsp</result>
    </action>
</package>

这是我得到的错误:

我做错了什么?我应该修复什么?

第一, 你已经给出了 namespace="/",所以你不需要在

中给出 "/"
<result name="success">/Index.jsp</result>

如果您有 namespace="/",请将其更改为以下内容

<result name="success">Index.jsp</result>

检查这是否解决了您的问题。检查 index.jsp 在第 0 个地址是否有 'i' 或 'I' 第二,
根据您的查询,我无法推断您的程序是否 运行 正常..
您是否测试了以下内容? * 在 "Class AddUser" 中删除验证方法中的所有 if 条件并放置 this

public void validate()
{
 System.out.println("in validate method");    
}

并且在执行方法中

public String execute()
{
 System.out.println("in execute method");    
 return SUCCESS; // assuming you are extending ActionSupport class & using default return types
}
  • 运行程序,检查输出如下图

预期输出
在验证方法中
在执行方法中
显示Index.jsp

如果您完成了此测试,请告诉我结果。如果上述方法有效,那么我们需要深入了解其他可能性。

已编辑
验证上述场景后,检查您从 actionMethod 返回的值:执行并验证从 action 方法返回的字符串是否存在于

的参数中

例如:

public String execute()
{
 return "hello";
}

并修改如下,去掉"error"和"input"

 <action name="AddUser" class="SIS.Student.AddUser"      method="execute">
  <!-- modified success to hello do debug with / and without /-->
  <result name="hello">index.jsp</result>
</action>