• 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 

    配置文件如下:

    <bean id="userController" class="com.demo.controller.UserController">

    <property name="userService" ref="userService"></property>

    <property name="myurl" value="userlist"></property>

    </bean>

    <bean id="viewResolver"

    class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">

    <property name="exposeRequestAttributes" value="true" />

    <property name="exposeSessionAttributes" value="true" />

    <property name="viewClass">

    <value>org.springframework.web.servlet.view.freemarker.FreeMarkerView</value>

    </property>

    <property name="cache">

    <value>true</value>

    </property>

    <property name="prefix">

     <value>/WEB-INF/ftl/

     </value> 

     </property>

    <property name="suffix">

    <value>.html</value>

    </property>

    <property name="contentType">

    <value>text/html; charset=UTF-8</value>

    </property>

    </bean>

    <bean id="simpleUrlMapping"

    class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

    <property name="mappings">

    <props>

    <prop key="/user.htm">userController</prop>

    </props>

    </property>

    </bean>

    <bean id="freemarkerConfig"

    class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">

    <property name="templateLoaderPath">

    <value>/WEB-INF/ftl/</value>

    </property>

    <property name="freemarkerSettings">

    <props>

    <prop key="locale">zh_CN</prop>

    <prop key="defaultEncoding">UTF-8</prop>

    <prop key="date_format">yyyy-MM-dd</prop>

    <prop key="time_format">HH:mm:ss</prop>

    <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>

    <prop key="number_format">0.################</prop>

    </props>

    </property>

    </bean>

    问题原因是因为freemarker本身配置了templateLoaderPath而在viewResolver中不需要配置prefix,且路径前缀必须配置在templateLoaderPath中

  • 相关阅读:
    制作计算器的代码(C#)
    Oracle如何实现创建数据库、备份数据库及数据导出导入操作
    XmlDocument类
    Android强大的开源库与系统架构工具
    IO
    胎压监测设备
    福施福、爱乐维、玛特纳各成分比较(已换算成同一单位)
    用车不容忽视的细节
    汽车必备车饰和常用物品
    j2ee指导型框架或示例
  • 原文地址:https://www.cnblogs.com/MIXP/p/7350656.html
Copyright © 2020-2023  润新知