java - Struts2请求数据封装时,提示:No result defined for action d_action
大家讲道理
大家讲道理 2017-04-18 10:31:04
0
2
482

写过您的点击进入,非常希望您能解答我的疑问:
刚刚开始学习Struts2,在进行Struts的请求数据封装功能时,提示:No result defined for action d_action.UserAction and result input,出现这个问题的原因已经定位到是Date类型的原因,网上有说是因为自己输入的格式不对,我也注意过这个问题了,但是并不能解决这个问题,最后会不会是数据验证的时候没有通过,但是Struts关于请求数据封装不是默认开启的吗?那么我的问题就是出在什么地方呢?
出现的异常是:

HTTP Status 404 - No result defined for action d_action.UserAction and result input

表单的jsp页面代码是:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>index</title>
  </head>
  <body>
  <form action="${pageContext.request.contextPath}/login1" method="post">
    用户名:<input type="text" name="name"> <br/>
    密码:<input type="text" name="pwd"> <br/>
    年龄:<input type="text" name="age"> <br/>
    生日:<input type="text" name="birth"> <br/>

    <input type="submit" value="注册">
  </form>
  </body>
</html>

然后是配置文件struts.xml的代码是:

<struts>
    <package name="action" extends="struts-default" namespace="/">
        <action name="login1" class="d_action.UserAction" method="register">
            <result name="success">/register.jsp</result>
            <!--<result name="input">/index.jsp</result>-->
        </action>
    </package>
</struts>

action的处理类代码是:

package d_action;



import com.opensymphony.xwork2.ActionSupport;

import java.util.Date;

/**
 *Struts核心业务,请求数据自动封装,以及类型转换
 */
public class UserAction extends ActionSupport{

    //封装请求数据
    private String name; //必须给set,get可以不用给
    private String pwd;
    private int age;
    private Date birth;

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

    public void setPwd(String pwd) {
        this.pwd = pwd;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setBirth(Date birth) {
        this.birth = birth;
    }


    //处理注册请求
    public String register(){
        System.out.println(name);
        System.out.println(pwd);
        System.out.println(age);
        System.out.println(birth);
        return "success";
    }
}

请大神指教!!

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
PHPzhong

1. Try commenting out the time field first
2. Give the time an initial value in the action
3. A very stupid way is to accept the time field as a string and convert it into a Date type
4. Use a special date control on the page

小葫芦

When requesting the data encapsulation function, it should be struts2 that intercepts birth. When the verification fails, the interceptor is intercepted by <interceptor name="workflow" class="com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor"/> The browser intercepted it, so it jumped to the input view.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template