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

写过您的点击进入,非常希望您能解答我的疑问:
刚刚开始学习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";
    }
}

请大神指教!!

大家讲道理
大家讲道理

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

모든 응답(2)
PHPzhong

1. 먼저 시간 필드를 주석 처리해 보세요
2. 작업의 시간에 초기 값을 지정하세요
3. 매우 어리석은 방법은 시간 필드를 문자열로 받아들인 다음 이를 문자열로 변환하는 것입니다. 날짜 유형
4 , 페이지에서 특별한 날짜 컨트롤을 사용하세요

小葫芦

데이터 캡슐화 기능을 요청할 때 struts2는 생성을 차단해야 합니다. 검증에 실패하면 <interceptor name="workflow" class="com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor"/> 입력뷰로 점프했습니다.

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿