Struts2日期型別轉換問題???

hechenhui1983發表於2009-06-30
我在jsp文字框中輸入日期格式的資料,在Action中使用Date型別接收時報錯,如果不輸入日期(使日期為空)或在Action中使用String型別來接收就不會報錯,這是為什麼???錯誤提示是找不到返回結果,這個錯誤和日期欄位有關係嗎,難道只是配置檔案寫錯了???如果和日期型別轉換有關係應該怎麼改???

錯誤:
11:44:40,640 ERROR Dispatcher:515 - Could not find action or result
No result defined for action www.account.people.struts.TestAction and result input - action - file:/E:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/webapps/account/WEB-INF/classes/config/struts/people/people-struts.xml:23:56
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:345)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48) ....


程式碼如下:

jsp程式碼:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here </title>
</head>
<body>
<form action=" <%=request.getContextPath()%>/test/toGo.shtml" method="post">
str: <input type="text" name="str" id = "str">
time: <input type="text" name="timee" id="timee">
<input type="submit" value="提交">
</form> </body>
</html>

Action程式碼:
public class TestAction extends BaseAction {

private Date timee;
private String str;
private String times;

public String toGo(){
System.out.println(times);
return super.SUCCESS;
}
public String getStr() {
return str;
}

public void setStr(String str) {
this.str = str;
}

public Date getTimee() {
return timee;
}

public void setTimee(Date timee) {
this.timee = timee;
}

public String getTimes() {
return times;
}

public void setTimes(String times) {
this.times = times;
}
}


struts2配置檔案:
<package name="test" namespace="/test" extends="struts-default">
<action name="toGo" class="testAction" method="toGo">
<!-- <result name="input">/index.jsp </result> -->
<result name="success">/index.jsp </result>
</action>
</package>


補充:
1.我後來把jsp使用struts2的標籤重新寫了一邊,日期也使用了struts2的日期控制元件,提交後還是報同樣的錯誤。。
2.按網上的一些說法我也新增了Date型別轉換類,xwork-conversion.properties配置也加上了,還是同樣的錯誤。。

相關文章