我在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>
[color=red]<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>[/color]
Action代码:
public class TestAction extends BaseAction { private Date timee;
private String str;
private String times; [color=#FF0000]public String toGo(){
System.out.println(times);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.format(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;
}
}[/color]
struts2配置文件:
<package name="test" namespace="/test" extends="struts-default">
<[color=red]action name="toGo" class="testAction" method="toGo">
<!-- <result name="input">/index.jsp</result> -->
<result name="success">/index.jsp</result>
</action>
</package>
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>
[color=red]<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>[/color]
Action代码:
public class TestAction extends BaseAction { private Date timee;
private String str;
private String times; [color=#FF0000]public String toGo(){
System.out.println(times);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.format(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;
}
}[/color]
struts2配置文件:
<package name="test" namespace="/test" extends="struts-default">
<[color=red]action name="toGo" class="testAction" method="toGo">
<!-- <result name="input">/index.jsp</result> -->
<result name="success">/index.jsp</result>
</action>
</package>
并且在这个类中提供getter和setter方法
因为页面传值的原因 相信为什么就不要我解释了吧
我的页面输入格式是:yyyy-MM-dd这样的。。
Action中的times这个字段是我测试"将接收转换成String类型时用的",和程序报的错误没有什么错误。。
随便说下,如果把页面上的文本框name=timee改成name=times,在Action中使用times字段接收程序可以正常运行,不报任何的错误。
当程序出现这种情况的时候,struts2会转到input
加上这句<result name="input">/index.jsp </result>还有一种解决办法,就是给个正确的时间.
选择时间的时候,建议使用strust2 标签.
哥们可以给个小例子吗,我把jsp中的标签都改成struts2的标签了,也使用了struts2提供的日期控件,还是报同样的错误,这个类型转换应该怎么解决呀???