我在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>

解决方案 »

  1.   

    自动类型转换错误默认action返回一个“input“ 所以要配置action一个name=“input“返回结果
      

  2.   

    可以加个数据类型转换类,然后在xwork-conversion.properties配置一下试试
      

  3.   

    首先,你肯定要配个input,或者你指定一个错误的配置也可以其次,用date类型是可以接的,但是输入格式要对,如2009-06-29这样的
      

  4.   

    找不到结果是因为你没配input,times为空,出错.time: <input type="text" name="timee" id="timee"> 改成time: <input type="text" name="times" id="times"> .
      

  5.   

       注意   页面<input type="text" name="timee">中的timee属性名一定要和TestAction 类中的属性名相同
       并且在这个类中提供getter和setter方法
      

  6.   

       并且  类中的属性一定是String型滴
           因为页面传值的原因  相信为什么就不要我解释了吧
      

  7.   

    我在返回类型中已经配了error,还是不成。。
    我的页面输入格式是:yyyy-MM-dd这样的。。
    Action中的times这个字段是我测试"将接收转换成String类型时用的",和程序报的错误没有什么错误。。
    随便说下,如果把页面上的文本框name=timee改成name=times,在Action中使用times字段接收程序可以正常运行,不报任何的错误。
      

  8.   

    你的程序出现了类型转换错误
    当程序出现这种情况的时候,struts2会转到input
    加上这句<result name="input">/index.jsp </result>还有一种解决办法,就是给个正确的时间.
    选择时间的时候,建议使用strust2 标签.
      

  9.   


    哥们可以给个小例子吗,我把jsp中的标签都改成struts2的标签了,也使用了struts2提供的日期控件,还是报同样的错误,这个类型转换应该怎么解决呀???
      

  10.   

    楼主没有考虑NULL值判断。NULL就不处理转换了撒,免得转换肯定报错,这跟你ERROR结果没关系,因为这是JAVA代码错误 强制中断。
      

  11.   

    建议楼主将action中的日期类型用String 类型来接收