我也觉得奇怪,所以我在Action.execute() 里面用 mapping.getInputForward();总是跳到一个空白页面去,
后来才发现 mapping.getInputForward() = null, 实在不知道问题出在哪里???

解决方案 »

  1.   

    <action    path="/test"
       type="org.apache.struts.webapp.example.TestAction"
               name="testForm" scope="session"
              input="/testInput.jsp" validate="true">
    有execute中直接根据判断来调用mapping.findForward("success");试试..
      

  2.   

    修改成下面这样就可以:    <action    path="/test"
                   type="org.apache.struts.webapp.example.TestAction"
                   name="testForm"
                  scope="request"
                  input="testInput">
              <forward name="testInput"         path="/testInput.jsp"/>
        </action>这样是可以的,
    我就不知道为什么直接在 input 里面填写 /testInput.jsp,
    mapping.getInput() 可以得到 "/testInput.jsp",
    但是 mapping.getInputForward() 却总是null???究竟是什么原因呢???在 struts-config_1_1.dtd文档里面也写了
    input: Module-relative path of the action or other resource to which control should be returned if a validation error is encountered. 并非一定要是 Module-relative path ,还可以是 other resource 啊, 
    怎么会不行呢???
      

  3.   

    我靠,这个叫没问题????拜托,这个就是你的代码吗,骗人的吧连return都没有怎么运行,不把全部代码拿来看还贴了这么段代码,你这不是找麻烦吗
    还有运行结果???
      

  4.   

    这位兄台,
    return当然是有的, 
    就是 return (mapping.getInputForward());
    因为总是跳到一个空白的页面去, 后来打印一下才知道 mapping.getInputForward()=null.其他的代码是无关紧要的, 因为并不影响 mapping.getInputForward()的值,所以没有贴出来.
      

  5.   

    是不是返回值是ActionForward?
    还是forward写在<global-forwards></global-forwards>中?
    不太懂,刚学,
      

  6.   

    <action    path="/test"
                   type="org.apache.struts.webapp.example.TestAction"
                   name="testForm"
                  scope="request"
                  input="testInput">
              <forward name="testInput"         path="/testInput.jsp"/>
        </action>这段话本来就没问题,但你在Action中的代码却有错,如下String input = mapping.getInput();
    ActionForward forward = mapping.getInputForward();  mapping.getInput()与mapping.getInputForward()得到的是两个不同值
    前者取出的是你的input里面的内容,针对这段代码来讲,取出的值是"testInput"
    后者取出的是根据你input里面的字符串来查找转向地址,也就是在当前mapping中
    <forward name="testInput"         path="/testInput.jsp"/> 
    等类似的转向里查找name值,在这段代码里查找将会匹配到forward name="testInput",而转向其指向的"/testInput.jsp"同样的道理,如果你在input 里写"/testInput.jsp"
    那么就应该有类似一句:
    <forward name="/testInput.jsp"         path="/testInput.jsp"/> 
      

  7.   

    bitou(大鹏一日同风起,扶摇直上九万里)://如果你在input 里写"/testInput.jsp"
    //那么就应该有类似一句:
    //<forward name="/testInput.jsp"         path="/testInput.jsp"/> 如果我有后面这句 <forward name="/testInput.jsp"         path="/testInput.jsp"/> 
    , 那么, 我就可以在 input 里面写 testInput 了.我想知道: 是不是 input 里面只能填写 后面定义的 <forward name="" path="..."> name 里面的内容?  只在 input 里面写"/testInput.jsp" 这样为什么不行?  
      

  8.   

    action中错了应改为
    public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) {
    String input = mapping.getInput();
    ActionForward forward = mapping.findForward("success"); 
    System.out.println(input); //testInput.jsp
    System.out.println(forward); //null
    }
    mapping.getInputForward();  你的配置文件里有两个forward你没指定那一个啊
      

  9.   

    lingjun1985(一切):  你没有看明白我的意思, 我如果直接指定 forward 就可以了, 我前面也说了.
      
      我是想知道: 直接在input属性里面指定 "/testInput.jsp" 为什么不行?
      

  10.   

    我想知道: 是不是 input 里面只能填写 后面定义的 <forward name="" path="..."> name 里面的内容?  只在 input 里面写"/testInput.jsp" 这样为什么不行?  
    -----------------------------------------------------------------input 里面的页面地址本来是在ActionForm里面验证失败时返回的页面
    但你在Action中调用到这一句
    ActionForward forward = mapping.getInputForward();  
    所以才会找你forward里面的内容如果
    input="/testInput.jsp">
    你也可以这样String path = mapping.getInput();
    ActionForward forward = new ActionForward();
    forward.setPath(request.getContextPath()+path);//因为是JSP,所以要加上下文根
    return forward;
    应该也能取得同样的效果
      

  11.   

    楼上完全正解!
    看看文档吧:
    public ActionForward getInputForward()
    Create (if necessary) and return an ActionForward that corresponds to the input property of this Action.
    ----------
    public java.lang.String getInput()
    Get the context-relative path of the input form to which control should be returned if a validation error is encountered.