首页 > 代码库 > springMVC+freemarker中Could not resolve view with name... 问题解决

springMVC+freemarker中Could not resolve view with name... 问题解决

用到springMVC+freemarker,自己在做demo过程中报:

严重: Servlet.service() for servlet springmvc threw exception

javax.servlet.ServletException: Could not resolve view with name ‘userlist‘ in servlet with name ‘springmvc‘

at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1102)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:890)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:851)

at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:756)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)

at 


<!-- Freemarker配置 -->  
    <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">  
        <property name="templateLoaderPath" value="http://www.mamicode.com//WEB-INF/views/" />  
        <property name="freemarkerSettings">  
            <props>  
                <prop key="template_update_delay">0</prop>  
                <prop key="default_encoding">UTF-8</prop>  
                <prop key="number_format">0.##########</prop>  
                <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>  
                <prop key="classic_compatible">true</prop>  
                <prop key="template_exception_handler">ignore</prop>  
            </props>  
        </property>  
    </bean>  
    <!--freemarker视图解析器-->  
    <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">  
        <property name="cache" value="http://www.mamicode.com/true"/>
        <property name="prefix" value="http://www.mamicode.com//WEB-INF/views/"/>
        <property name="suffix" value="http://www.mamicode.com/.html"/>
        <property name="contentType" value="http://www.mamicode.com/text/html;charset=UTF-8" />
        <!--if you want to use the Spring FreeMarker macros, set this property to true-->
        <property name="exposeSpringMacroHelpers" value="http://www.mamicode.com/true"/>
        <property name="requestContextAttribute" value="http://www.mamicode.com/requestContext" />
    </bean>   

 问题解决:
因为freemarker本身配置了templateLoaderPath而在viewResolver中不需要配置prefix。


来自为知笔记(Wiz)


springMVC+freemarker中Could not resolve view with name... 问题解决