发布图块(无法解析名称为...的视图)

时间:2014-07-14 04:14:04

标签: spring-mvc tiles

我正在使用Spring MVC。我的应用程序在插入tile之前没问题,现在我一直收到错误消息:

javax.servlet.ServletException: Could not resolve view with name '/sisStudent' in servlet with name 'mvc-dispatcher'
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1190)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

我的tiles.xml是:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC 
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" 
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
    <definition name="base.definition" template="/WEB-INF/jsp/layout.jsp">
        <put-attribute name="title" value="" />
        <put-attribute name="header" value="/WEB-INF/jsps/header.jsp" />
        <put-attribute name="menu" value="/WEB-INF/jsps/menu.jsp" />
        <put-attribute name="body" value="" />
        <!-- put-attribute name="footer" value="/WEB-INF/jsps/footer.jsp" /> -->
    </definition>
    <definition name="sisStudent" extends="base.definition">
        <put-attribute name="title" value="SIS Students" />
        <put-attribute name="body" value="/WEB-INF/jsps/sisStudent.jsp" />
    </definition>
</tiles-definitions>

我的spring-servlet.xml是:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <context:component-scan base-package="au.edu.nsw.det.tls.tar.sis.controller" />
    <!--
        bean id="tilesViewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        property name="prefix"> <value>/WEB-INF/jsps/</value> </property>
        <property name="suffix"> <value>.jsp</value> </property> <property
        name="viewClass"> <value>
        org.springframework.web.servlet.view.tiles3.TilesView</value>
        </property> </bean>
    -->
    <!-- bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/jsps/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value> org.springframework.web.servlet.view.tiles3.TilesView</value>
        </property>
    </bean>
    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>
</beans>

我的控制器是:

@Controller
// @RequestMapping("/studentSearch")
public class StudentSearchController {

    @Autowired
    StudentService studentService;

    // @RequestMapping(value="/StudentSearchById", method = RequestMethod.GET)
    // public ModelAndView searchById(@PathVariable Long studentId) {

    @RequestMapping (value="/openStudentSearchScreen", method = RequestMethod.GET)
    public ModelAndView openCourseSearchScreen(){       
        ModelAndView modelAndView = new ModelAndView("/sisStudent");        
        return modelAndView;
    }

}

有什么想法吗?

提前谢谢!

1 个答案:

答案 0 :(得分:2)

ModelAndView构造函数中删除前导/,以便

@RequestMapping (value="/openStudentSearchScreen", method = RequestMethod.GET)
public ModelAndView openCourseSearchScreen(){       
    ModelAndView modelAndView = new ModelAndView("sisStudent");        
    return modelAndView;
}    

OTOH Insted of ModelAndView您可以使用String

@RequestMapping (value="/openStudentSearchScreen", method = RequestMethod.GET)
public String openCourseSearchScreen(){       
    return "sisStudent";//Tiles definition name        
}

如果要添加一些模型属性

@RequestMapping (value="/openStudentSearchScreen", method = RequestMethod.GET)
public String openCourseSearchScreen(Model model){       
    model.addAttribute("<name of the attribute>",<value as object>);
    return "sisStudent";//Tiles definition name        
}