寫過(guò)您的點(diǎn)擊進(jìn)入,非常希望您能解答我的疑問(wèn):
剛剛開(kāi)始學(xué)習(xí)Struts2,在進(jìn)行Struts的請(qǐng)求數(shù)據(jù)封裝功能時(shí),提示:No result defined for action d_action.UserAction and result input
,出現(xiàn)這個(gè)問(wèn)題的原因已經(jīng)定位到是Date類型的原因,網(wǎng)上有說(shuō)是因?yàn)樽约狠斎氲母袷讲粚?duì),我也注意過(guò)這個(gè)問(wèn)題了,但是并不能解決這個(gè)問(wèn)題,最后會(huì)不會(huì)是數(shù)據(jù)驗(yàn)證的時(shí)候沒(méi)有通過(guò),但是Struts關(guān)于請(qǐng)求數(shù)據(jù)封裝不是默認(rèn)開(kāi)啟的嗎?那么我的問(wèn)題就是出在什么地方呢?
出現(xiàn)的異常是:
HTTP Status 404 - No result defined for action d_action.UserAction and result input
表單的jsp頁(yè)面代碼是:
<%@ 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="注冊(cè)">
</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核心業(yè)務(wù),請(qǐng)求數(shù)據(jù)自動(dòng)封裝,以及類型轉(zhuǎn)換
*/
public class UserAction extends ActionSupport{
//封裝請(qǐng)求數(shù)據(jù)
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;
}
//處理注冊(cè)請(qǐng)求
public String register(){
System.out.println(name);
System.out.println(pwd);
System.out.println(age);
System.out.println(birth);
return "success";
}
}
請(qǐng)大神指教?。?/p>
光陰似箭催人老,日月如移越少年。
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.