Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring3MVC-模型未显示在JSP页面中_Java_Jsp_Spring Mvc_Model_Apache Tiles - Fatal编程技术网

Java Spring3MVC-模型未显示在JSP页面中

Java Spring3MVC-模型未显示在JSP页面中,java,jsp,spring-mvc,model,apache-tiles,Java,Jsp,Spring Mvc,Model,Apache Tiles,从表面上看,这个问题听起来很像以前在SOF上问过的问题,但我很久以前就尝试过这些答案,但没有运气 比如说这个问题, 因此,我有一个扩展了CancelableFormController的Spring 2.0控制器,它包含以下内容,用于将命令对象绑定到JSP页面呈现上的表单: public class MyFormController extends CancellableFormController { .... protected Object formBackingObject(

从表面上看,这个问题听起来很像以前在SOF上问过的问题,但我很久以前就尝试过这些答案,但没有运气

比如说这个问题,

因此,我有一个扩展了CancelableFormController的Spring 2.0控制器,它包含以下内容,用于将命令对象绑定到JSP页面呈现上的表单:

public class MyFormController extends CancellableFormController {

....

    protected Object formBackingObject(HttpServletRequest request) throws ServletException {
        MyCommand myCommand = new MyCommand();
            ... // add some list info to command object etc in preparation for page render
        return myCommand;
    }

....

}
JSP页面看起来如下所示:

<form:form method="post" commandName="myCommand">

    <c:forEach items="${myCommand.myList}" var="myItem" varStatus="index">

</form:form>
然后,我尝试了以下每种方法,控制器类构造与上述相同:

@RequestMapping(method = RequestMethod.GET)
@ModelAttribute("myCommand")
public String initForm(HttpServletRequest request, HttpServletResponse response) throws Exception {
      MyCommand myCommand = new MyCommand();
      ....
      return "myTilesViewName";
}

@RequestMapping(method = RequestMethod.GET)
public String initForm(ModelMap model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    MyCommand myCommand = new MyCommand();
    ...
    model.addAttribute("myCommand", cmd);
    return "myTilesViewName";
}
我不想增加任何混乱。我想,如果我只是返回JSP页面的视图名,那么这个问题的答案可能是相同的。。。但是,我使用ApacheTiles来处理页面选择。我的定义如下:

<definition name="myTilesViewName" extends=".myTemplate">
    <put-attribute name="title" value="MyTitle" type="string" />
    <put-attribute name="body" value="/WEB-INF/jsp/myPage.jsp" />
</definition>
请记住,在使用Spring2 CancelableFormController代码之前,一切都工作得很好。我根本没有改变Tiles配置或JSP页面,所以不要认为它们是这个问题的根源

非常感谢任何能提供帮助的人。我们当然很感激

更新: 这个问题最后涉及到一个客户端JSP页面相关问题。我认为除了控制器之外没有任何变化是不正确的。真诚的道歉,谁花时间阅读这个帖子,并考虑解决方案。对于其他有相同症状的阅读者,请仔细检查您的视图页面JSP,并确保它们在呈现时语法正确。在我的例子中,我将一个包含大约2000行代码的JSP移动到一个子文件夹中,并断开了一个到嵌套JSP导入声明的相对链接

<definition name="myTilesViewName" extends=".myTemplate">
    <put-attribute name="title" value="MyTitle" type="string" />
    <put-attribute name="body" value="/WEB-INF/jsp/myPage.jsp" />
</definition>