我想写个对piont自定义转换的程序可是出现了如下的错误
2008-12-7 18:43:10 org.apache.struts2.dispatcher.Dispatcher serviceAction
严重: Could not find action or result
No result defined for action com.test.PointAction and result input - action - file:/E:/Documents%20and%20Settings/Administrator/workspace/struts2/WebRoot/WEB-INF/classes/struts.xml:13:62
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:350)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:253)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:186)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
我的源文件如下
LoginActin.java文件。
package com.test;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {
/**
 * 
 */
private static final long serialVersionUID = 1L;
String username;
String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String  execute()throws Exception
{
if("hello".equals(this.getUsername().trim())&&"world".equals(this.getPassword().trim()))
{
return "success";
}
else
{
this.addFieldError("password", "username or password is Error");
return "failer";
}
}
public void validate() {
// TODO Auto-generated method stub
if(null==this.getUsername()||"".equals(this.getUsername().trim()))
{
this.addFieldError("username", "username is null");

}
if(null==this.getPassword()||"".equals(this.getPassword().trim()))
{
this.addFieldError("password", "password is null");

}
}
}

解决方案 »

  1.   

    Piont.java文件
    package com.test.bean;public class Point {
    private int x;
    private int y;
    public int getX() {
    return x;
    }
    public void setX(int x) {
    this.x = x;
    }
    public int getY() {
    return y;
    }
    public void setY(int y) {
    this.y = y;
    }}
    PointAction.java文件package com.test;
    import java.util.Date;
    import com.opensymphony.xwork2.ActionSupport;
    import com.test.bean.Point;
    public class PointAction extends ActionSupport {
    /**
     * 
     */

    private Point point=null;
    private int age ;
    private String username;
    private Date birthday;
    public Point getPoint() {
    return point;
    }
    public void setPoint(Point point) { this.point = point;
    }
    public int getAge() {
    return age;
    }
    public void setAge(int age) {
    this.age = age;
    }
    public String getUsername() {
    return username;
    }
    public void setUsername(String username) {
    this.username = username;
    }
    public Date getBirthday() {
    return birthday;
    }
    public void setBirthday(Date birthday) {
    this.birthday = birthday;
    }
    public String execute() throws Exception {
    // TODO Auto-generated method stub

    return SUCCESS;
    }
    }
    struts.xml文件
    <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
    <package name="struts2" extends="struts-default">
    <action name="login" class="com.test.LoginAction">
    <result name="input">/login3.jsp</result>
    <result name="success">/result.jsp</result>
    <result name="failer">/login3.jsp</result>
    </action>
    <action name="pointConverter" class="com.test.PointAction">
         
         <result name="success">/output.jsp</result>
    </action>
        </package>
    </struts>
      

  2.   

    和PointAction.java同目录下的PointAction-conversion.properties文件
    Point=com.coverter.PointConverterPointConverterv.java文件
    package com.coverter;
    import java.util.Map;import com.test.bean.Point;import ognl.DefaultTypeConverter;public class PointConverter extends DefaultTypeConverter { public Object convertValue(Map context, Object value, Class toType) {
    // TODO Auto-generated method stub
    if(Point.class==toType)
    {
    Point point=new Point();
    String []str=(String [])value;
    String []paramValue=str[0].split(",");
    int x=Integer.parseInt(paramValue[0]);
    int y=Integer.parseInt(paramValue[1]);
    point.setX(x);
    point.setY(y);
    return point;
    }
    if(String.class==toType)
    {
    Point point =(Point)value;
    int x=point.getX();
    int y=point.getY();
        String result="[x="+x+","+"y="+y+"]";
        return result;
    }
    else 
    return null;
    }}
      

  3.   

    login2.jsp文件如下
    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <%@taglib prefix="s" uri="/struts-tags" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>"> <title>My JSP 'login2.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    --> </head>
    <h3>please input dou hao </h3>
      <body>
        <s:form action="pointConverter">
        <s:textfield name="point" label="point"> </s:textfield>
        <s:textfield name="age" label="age"></s:textfield>
        <s:textfield name="username" label="username"></s:textfield>
        <s:textfield name="birthday" label="birthday"></s:textfield>
        <s:submit label="submit"></s:submit>
        </s:form>
         
    </body>
    </html>
    当输入信息后出现如下错误
    type Status reportmessage No result defined for action com.test.PointAction and result inputdescription The requested resource (No result defined for action com.test.PointAction and result input) is not available.
      

  4.   

    提示很明确啊
    No result defined for action com.test.PointAction and result input - action - file:/E:/Documents%20and%20Settings/Administrator/workspace/struts2/WebRoot/WEB-INF/classes/struts.xml:13:62 
    你仔细检查一下你的配置文件
      

  5.   

    应该配置<result name="input">画面位置</input>
    原因:在类型转换发生错误后,要显示错误信息。必须配置input。
      

  6.   


    我的PointAction明明只返回了success怎么会有input呢
      

  7.   

    jsp页面的form的validation没有通过,要对应的action定义<result name="input">
      

  8.   

    我只是做了个简单的转换即对输入的point坐标值做转换在action里直接返回了success 根本就没有用到input的地方
      

  9.   

    转换的时候,发生错误会返回到INPUT,这是转换器里面的,根你自己再action里面设没设没关系,默认的。
      

  10.   

    你是看网上的教程做的吧  我今天下午也郁闷了一午  也是同样的毛病 
    找了一下午 最后通过比较 才发现自己的转型类中自己多敲了一行代码if (Point.class == toType) {
    Point point = new Point();
    String values[] = (String[]) value;
    String parameter[] = values[0].split(",");
    !!!!!!!!//System.out.println(values[1]);
    int x = Integer.parseInt(parameter[0]);
    int y = Integer.parseInt(parameter[1]);
    point.setX(x);
    point.setY(y);
    return point;
    }
    只是为了试试能否输出。 我发现用Struts2时报错机制实在是差的可怜 要是用servlet什么的  一眼就能看出来的  真不知道以后找错会是个什么样子
      

  11.   

    当你在用struts2开发时,如果,从页面跳入action时,页面报No result defined for action and result时,大部分的原因有以下几种:1、validate方法没有通过;2、页面元素中有重命名时,但后台action类的对应的接收此同名参数的是变量而没有写成数组,这个极有可能,我就碰到过,搞了好久才发现是这个原因
    要检查这种错误时,可以
    1,在后台action类中重写ActionSupport中的
    void addActionError(String anErrorMessage)
    void addActionMessage(String aMessage)
    void addFieldError(String fieldName, String errorMessage)
    这三个方法,在并在其实现代码中设置断点,监控传入的参数,并可获知页面的相关报错具体原因.
    2,在页面中加入以下标签,将错误显示出来:
    <div style=”color:red”>
        <s:fielderror />
    </div>
      

  12.   

    和PointAction.java同目录下的PointAction-conversion.properties文件
    Point=com.coverter.PointConverterpublic class PointConverter extends DefaultTypeConverter {public Object convertValue(Map context, Object value, Class toType) {
    // TODO Auto-generated method stub
    if(Point.class==toType)
    {
    Point point=new Point();这里错了吧,属性文件里的属性(是属性的名字不是属性所属类的名字)应该和action类里的属性的名字一样(注意大小写)。
    出现上述问题的一个常见原因就是把属性文件的名字写错( 被类型转换的action的类名-conversion.properties 例如PointAction中有对象类型的属性需要转换类型,那么在PointAction的同级目录里就应该有个PointAction-conversion.properties(红色的为固定不变的) 文件,那么在)或者里面的内容写错了。
      

  13.   

    struts2.1.8 必须配置namespace
    在2.0中一切OK,没有问题,但是在2.1中确出现了No result defined for action的异常,郁闷了好半天,经过多方查找,原来是在2.1中有一个插件struts2-convention-plugin-2.1.8.jar,这个插件是2.1版本中新添加的默认核心包,这个插件是实现Struts2的零配置(稍后会详细解释这个插件的使用),但是这样问题就来了,如果引入就必须引入namespace命名空间,否则就会出现刚才的No result defined for action的异常
    复制别人的......
    我也出现这个问题
      

  14.   


    感谢,我加上namaspace就好了。
      

  15.   


    我的解决办法是:
    :改/uapSecond/WebRoot/jsp/uaphost/uaphostlist.jsp为/uapSecond/WebRoot/jsp/uaphost/uaphost.jsp
    jsp的命名应该是有内在约定
      

  16.   

    <body>
      <s:form action="pointConverter">
      <s:textfield name="point" label="point"> </s:textfield>
      <s:textfield name="age" label="age"></s:textfield>
      <s:textfield name="username" label="username"></s:textfield>
      <s:textfield name="birthday" label="birthday"></s:textfield>
      <s:submit label="submit"></s:submit>
      </s:form>
        
    </body>
    红色部分写错了,把label改为type,试试!!!!!!!!!!!!
      

  17.   

    if (Point.class == toType) {
                Point point = new Point();
                String values[] = (String[]) value;
                String parameter[] = values[0].split(",");
            !!!!!!!!//System.out.println(values[1]);
                int x = Integer.parseInt(parameter[0]);
                int y = Integer.parseInt(parameter[1]);
                point.setX(x);
                point.setY(y);
                return point;
            }
      

  18.   

    if (Point.class == toType) {
                Point point = new Point();
                String values[] = (String[]) value;
                String parameter[] = values[0].split(",");
            !!!!!!!!//System.out.println(values[1]);
                int x = Integer.parseInt(parameter[0]);
                int y = Integer.parseInt(parameter[1]);
                point.setX(x);
                point.setY(y);
                return point;
            }
      

  19.   

    struts.xml中所配置的<action name="poinConvert" class="com.LoginAction">与页面(.jsp)<from action="poinConvert">中的action应该是相对应,这是没有什么质疑的!就是发这个...我以为这样是肯定没错的,但是经查询,我作了以下的改动:<action name="PoinConvert" class="com.LoginAction">与<from action="PoinConvert">当然同时改,去试试结果成功运行!意外...我又去看了其的地方,以为是把其它地方的类型转换的词改才正确的,但又仔细看了看不然,就是因为actio值的大小写问题所导致的!转载的。确实是这样的
      

  20.   

    看看你方法的名字,很有可能是你的action和配置中有某个名称不配对不上
      

  21.   

    <struts>
    <constant name="struts.devMode" value="true"></constant>
    <package name="struts2" extends="struts-default" namespace="/">
    <action name="addSchedule" class="com.qhit.myoffice.schedule.action.AddScheduleAction">
    <result name="success">page/scheduleManage/addSchedule.jsp</result>
    <result name="input">page/scheduleManage/addSchedule.jsp</result>
    </action>
    <action name="myScheduleList" class="com.qhit.myoffice.schedule.action.MyScheduleListAction">
    <result name="success">page/scheduleManage/MyScheduleList.jsp</result>
    <result name="input">page/scheduleManage/MyScheduleList.jsp</result>
    </action>
    <action name="mynote" class="com.qhit.myoffice.schedule.action.MynoteAction">
    <result name="success">page/scheduleManage/MyNote.jsp</result>
    <result name="input">page/scheduleManage/MyNote.jsp</result>
    </action>
    </package>
    </struts>    我的还是那种错误
      

  22.   

    Timestamp beginTime=ServletActionContext.getRequest().getParameter("beginTime");
    Timestamp endTime=ServletActionContext.getRequest().getParameter("endTime");
    这个总是报错,请问这个怎么转换啊
      

  23.   

    今天在编程的时候,我遇到了No result defined for action and result input的错误,这个错误想必大家都有遇到过吧,我今天发了很长时间弄这个错误,我以为我的Action函数出错了想调试,但是程序就是不进入断点,上网查资料,有的说路径错误啦,然后我找我的路径错误,搞了半天还是没发现有路径问题。然后我给我的属性的get方法都弄上了断点,我发现了问题,现在跟大家分享。 
        这个错误就是说没有为返回的input定义,可是有时候我们不一定要这个鬼东西,然而在Action中出错的话,默认就返回了这个input了,这时,我们在struts的<result>中定义的话,就出现No result defined for action and result input的错误了。 
        引起这个错误的原因是很多的,路径错误也是其中的一种,我这里的问题是,我的页面上的类型和我定义的属性的类型不一致,我的属性是int型的,但是在页面上输出的时候加了一个逗号,用了分割千位的,结果就出现了这个问题了。 
      

  24.   

    我也遇到这样的问题了。我在更改validation 那个验证文件。我做个action全局验证。就报错。要是Action-save-validation.xml 就没有问题
    怎么办。 );
      

  25.   

    这个是属性文件里的point的P大写了
      

  26.   

    有可能是你自定义的login拦截器里用了return Action.INPUT;(当用户还没有登录时,返回到input指定的页面)所以它会返回找input的result,而此时你根本就没有配置<result type="input">……</result>,也就出现了上面的错误。
    解决方法:1)、要么在struts.xml中配置一个<result type="input">;
              2)、修改自定义的login的拦截器里面的return Action.INPUT;为你登录失败的type.比如:return Action.ERROR;或者return Action.LOGIN;
      

  27.   

    action大小写敏感问题,form中的action和struts.xml中中的action必需大写!!!
      

  28.   

    我的struts2是2.2的 我加了namespace=""后就一切OK了
      

  29.   

    要加namespace=“” 我解决了
      

  30.   

    我有遇到了这个问题。我的解决方案是在sturt.xml中加了一个<result name="input">/Input.jsp</result>
      

  31.   

    遇到相同的问题 action需要大写
      

  32.   

    Struts2的Convention插件导致”No result defined for action”
    参见: http://ljt.me/?p=282
    Convention插件自动注册Action的功能让我们从struts.xml配置的繁杂工作中解放出来,但有时候也能带来一些麻烦。出现”No result defined for action”错误就是其中之一。
    比如我们在struts.xml中定义了一个名为logout的action,…action.LogoutAction是其实现类,这时Convention就会试图帮我们注册一个名叫logout的action,并搜索对应的jsp文件注册为result;如果xml文件和convention搜索出来的action重名,其缺省的原则是覆盖xml文件中的配置,这样我们原来在xml中定义的名为logout的action的result就没有了,于是出现了”No result defined for action”的错误。在我们不了解这个原则的时候一定很诧异:我明明定义了result,为什么报错说没有呢?其实就是被convention自动覆盖了。当我们知道了这个原则之后,就可以想办法避免了,首先xml定义action名字的时候避免和convention映射生成的action名字重复(需先了解convention的映射原则),convention是机械化的映射,而我们在xml文件中配置的aciton名字是可以根据需要进行修改的;其次如果可以的话,按convention的命名要求定义好jsp文件放到convention的result搜索路径中,这样convention就会自动注册result,不会再出现本文标题所示的错误了。多说一句,如何查看convention注册的action呢?答案是:struts2-config-browser-plugin,安装很简单,只需要复制到WEB-INF/lib中即可,使用也很简单,访问项目路径的/config-browser/子目录即可,当然了,这个插件并不是为convention设计的,它能显示所有在struts中注册的action,无论是否由convention注册。
      

  33.   

    其实就是jsp页面上传入的类型和action中得类型不一致,而struts2自动转换失败;请检查页面的数据类型。我的就是,我的多了一对单引号;如:<a href="findstu_del?pageNo='<s:property value="pager.nextPageNo" />'"> 而我要的是int,所以应该是这样才对<a href="findstu_del?pageNo=<s:property value="pager.nextPageNo" />">
      

  34.   

    Yes,这是这个错,我也被困扰了好久......
      

  35.   

    刚刚也遇到了这个问题~最后才发现是拼写错误 action与properties的文件名写错了~
      

  36.   

    我用的是 struts2.18 我发现只要把struts.xml中的<action="aaaaa" 改成<action ="Aaaaa"
    和jsp中的 <form action="aaaaa" 改成<form action="Aaaaa"
      

  37.   

    楼主的问题和我一样,返回SUCCESS。说明操作成功了。但还是报错,楼主找到了问题所在吗?