javax.servlet.ServletException: Could not resolve view with name 'xxxxx'in servlet with name 'xxx'
出现如上问题的解决方案:
第一,springmvc的配置文件中
<bean id="freemarkerConfig"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath"
value="/templates/" />
<property name="defaultEncoding" value="utf-8" />
模版加载地址配置是否正确 value="/templates/"
在controller中返回的页面地址需去掉默认加载路径 ( templates/login.ftl) 需去掉 templates
第二,返回json格式的数据的时候需注意 在配置文件中配置的
<property name="defaultContentType" value="text/html" />改为<property name="defaultContentType" value="application/json" />
本文解决了一个关于SpringMVC框架中无法解析特定视图名称的问题,主要涉及配置文件中视图解析器的设置错误,包括模板加载路径不正确及JSON数据返回格式配置不当等问题。

被折叠的 条评论
为什么被折叠?



