Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符

J2EE 码拜 10年前 (2015-04-14) 1387次浏览 0个评论

初次使用Freemarker,在整合Spring mvc时出现在ftl页面中标签直接显示出来了,如下图:

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符

搞了很久,都没找出问题所在,工程配置如下:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="cms" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			classpath:spring/applicationContext*.xml
		</param-value>
	</context-param>

	<!-- spring mvc 配置 -->
	<servlet>
		<servlet-name>springmvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<!-- spring 配置文件,名称的路径都可以配置,如果不配置此项则自动扫描/WEB-INF/springmvc-servlet.xml,此文件名规则为servlet名-servlet.xml -->
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring/springmvc-*.xml</param-value>
			<!-- 加载多个配置文件 <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/conf/applicationContext_*.xml, 
				/WEB-INF/conf/user-servlet.xml </param-value> -->
		</init-param>
		<!--servlet加载方式,启动容器时加载 -->
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>springmvc</servlet-name>
		<!-- 拦截所有请求 -->
		<url-pattern>*.action</url-pattern>
	</servlet-mapping>

	<filter>
		<filter-name>characterEncodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>

	<filter-mapping>
		<filter-name>characterEncodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- spring 加载log4j配置文件 -->
	<context-param>
		<param-name>log4jConfigLoaction</param-name>
		<param-value>classpath:log4j.properties</param-value>
	</context-param>

	<!-- 刷新Log4j配置文件的间隔,60秒 -->
	<context-param>
		<param-name>log4jRefreshInterval</param-name>
		<param-value>60000</param-value>
	</context-param>

	<!--可选配置,定义web 应用的别名,如果不设置,缺省为"webapp.root",当tomcat加载多个项目时,会发生名称冲突 -->
	<context-param>
		<param-name>webAppRootKey</param-name>
		<param-value>webName.root</param-value>
	</context-param>
    
    <!-- 静态资源处理 -->
	<servlet-mapping>
		<servlet-name>default</servlet-name>
		<url-pattern>*.css</url-pattern>
		<url-pattern>*.gif</url-pattern>
		<url-pattern>*.js</url-pattern>
		<url-pattern>*.jpg</url-pattern>
	</servlet-mapping> 

	<!-- Spring 加载 Log4j 的监听器 -->
	<listener>
		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
	</listener>
	<!-- 防止内存泄漏 -->
	<listener>
		<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
	</listener>

    <!-- init servlet -->
	<servlet>
		<servlet-name>SystemInitServlet</servlet-name>
		<servlet-class>
			com.dhf.cms.init.SystemInitServlet
		</servlet-class>
		<load-on-startup>10</load-on-startup>
	</servlet>

	<welcome-file-list>
		<welcome-file>base/admin/index.action</welcome-file>
	</welcome-file-list>

	<error-page>
		<error-code>500</error-code>
		<location>/WEB-INF/view/error500.jsp</location>
	</error-page>
	<error-page>
		<error-code>404</error-code>
		<location>/WEB-INF/view/error404.jsp</location>
	</error-page>

</web-app>

springmvc-servlet.xml也加入了:

 <!-- Freemarker配置 -->
	<bean id="freemarkerConfig"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<property name="templateLoaderPath" value="/WEB-INF/view/" />
		<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>
	<!--视图解释器 -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
		<property name="suffix">
			<value>.ftl</value>
		</property>
		<property name="contentType" value="text/html;charset=UTF-8"></property>
	</bean> 

Controller代码:

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.dhf.cms.base.bean.AdminInfo;
import com.dhf.cms.base.bean.BaseBean;
import com.dhf.cms.base.service.AdminService;
import com.dhf.cms.global.LogKeys;
import com.dhf.cms.global.ReturnCode;
import com.dhf.cms.init.manager.PropertiesManager;
import com.dhf.cms.response.BaseResponse;
import com.dhf.cms.tool.Coder;
import com.dhf.cms.tool.CommonTool;
import com.dhf.cms.validation.Validationor;

@Controller
@RequestMapping(value = "base/admin")
public class AdminController
{
    
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public ModelAndView index(HttpServletRequest request)
    {
        Map<String,String> map = new HashMap<String,String>();
        map.put("name", "dinghuafeng");
        request.setAttribute("name", "message is added");
        ModelAndView mv = new ModelAndView("index");
        mv.addObject("name","aaaabbbbb");
        //return new ModelAndView("/index",map);
        return mv;
    }
}

通过http://localhost:8080/cms/base/admin/index.action跳转都是正常,就是标签取值无法显示,是不是Freemarke还依赖了其他的包?请各位大侠解救,谢谢!

引入包如下:

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
10分
 Maybe 
<bean id=”viewResolver”
        class=”org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver”>
        <property name=”suffix”>
            <value>.ftl</value>
        </property>
        <property name=”contentType” value=”text/html;charset=UTF-8″></property>
    </bean> 
Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
看了下,楼主好像是参照这个写的吧?http://blog.csdn.net/yakson/article/details/9813531

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
建议看看完整的FreeMarkerViewResolver配置   

http://liuxlyard.iteye.com/blog/1156081

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
引用 3 楼 shijing266 的回复:

建议看看完整的FreeMarkerViewResolver配置   

http://liuxlyard.iteye.com/blog/1156081

行,我试试看!

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
改成这样 类似的试试:
<bean id=”viewResolver”
class=”org.springframework.web.servlet.view.InternalResourceViewResolver”>
<property name=”prefix”>
<value>/jsp/</value>
</property>
<property name=”suffix”>
<value>.jsp</value>
</property>
<property name=”order” value=”1″ />
</bean>
Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
引用 4 楼 dingding5060 的回复:
Quote: 引用 3 楼 shijing266 的回复:

建议看看完整的FreeMarkerViewResolver配置   

http://liuxlyard.iteye.com/blog/1156081

行,我试试看!

好的,最好告诉我结果,还有如果有异常,请贴出异常信息..

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
引用 4 楼 dingding5060 的回复:
Quote: 引用 3 楼 shijing266 的回复:

建议看看完整的FreeMarkerViewResolver配置   

http://liuxlyard.iteye.com/blog/1156081

行,我试试看!

按照这个例子,还是:

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符

加入代码如下:


<!-- 定义FreeMarker视图解析器与属性配置 -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
		<property name="cache" value="true" />
		<property name="prefix" value="" />
		<property name="suffix" value=".ftl" />
		<property name="viewClass"
			value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
		<property name="exposeSpringMacroHelpers" value="true" />
		<property name="exposeRequestAttributes" value="true" />
		<property name="exposeSessionAttributes" value="true" />
		<property name="requestContextAttribute" value="rc" />
		<property name="contentType" value="text/html;charset=UTF-8" />
	</bean>

	<bean id="freemarkerConfig"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<property name="templateLoaderPath" value="/WEB-INF/view/" />
		<property name="freemarkerSettings">
			<props>
				<prop key="template_update_delay">5</prop>
				<prop key="defaultEncoding">UTF-8</prop>
				<prop key="url_escaping_charset">UTF-8</prop>
				<prop key="locale">zh_CN</prop>
				<prop key="boolean_format">true,false</prop>
				<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
				<prop key="time_format">HH:mm:ss</prop>
				<prop key="number_format">0.######</prop>
				<prop key="whitespace_stripping">true</prop>
			</props>
		</property>
	</bean> 

index.ftl代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   
 "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
    <head>  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
        <title>${title}</title>  
    </head>  
    <body>  
        ${name}  
    </body>  
</html> 
Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
引用 6 楼 shijing266 的回复:
Quote: 引用 4 楼 dingding5060 的回复:
Quote: 引用 3 楼 shijing266 的回复:

建议看看完整的FreeMarkerViewResolver配置   

http://liuxlyard.iteye.com/blog/1156081

行,我试试看!

好的,最好告诉我结果,还有如果有异常,请贴出异常信息..

后台无异常,没有任何错误!后台截图如下:

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
引用 7 楼 dingding5060 的回复:
Quote: 引用 4 楼 dingding5060 的回复:
Quote: 引用 3 楼 shijing266 的回复:

建议看看完整的FreeMarkerViewResolver配置   

http://liuxlyard.iteye.com/blog/1156081

行,我试试看!

按照这个例子,还是:

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符

加入代码如下:


<!-- 定义FreeMarker视图解析器与属性配置 -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
		<property name="cache" value="true" />
		<property name="prefix" value="" />
		<property name="suffix" value=".ftl" />
		<property name="viewClass"
			value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
		<property name="exposeSpringMacroHelpers" value="true" />
		<property name="exposeRequestAttributes" value="true" />
		<property name="exposeSessionAttributes" value="true" />
		<property name="requestContextAttribute" value="rc" />
		<property name="contentType" value="text/html;charset=UTF-8" />
	</bean>

	<bean id="freemarkerConfig"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<property name="templateLoaderPath" value="/WEB-INF/view/" />
		<property name="freemarkerSettings">
			<props>
				<prop key="template_update_delay">5</prop>
				<prop key="defaultEncoding">UTF-8</prop>
				<prop key="url_escaping_charset">UTF-8</prop>
				<prop key="locale">zh_CN</prop>
				<prop key="boolean_format">true,false</prop>
				<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
				<prop key="time_format">HH:mm:ss</prop>
				<prop key="number_format">0.######</prop>
				<prop key="whitespace_stripping">true</prop>
			</props>
		</property>
	</bean> 

index.ftl代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   
 "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
    <head>  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
        <title>${title}</title>  
    </head>  
    <body>  
        ${name}  
    </body>  
</html> 

恩,改了配置没?  现在可以了么?  还是原来的? 现在用的是jsp还是html

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
引用 5 楼 xuemingyuan88 的回复:

改成这样 类似的试试:
<bean id=”viewResolver”
class=”org.springframework.web.servlet.view.InternalResourceViewResolver”>
<property name=”prefix”>
<value>/jsp/</value>
</property>
<property name=”suffix”>
<value>.jsp</value>
</property>
<property name=”order” value=”1″ />
</bean>

按照指示将试图解析类改为:InternalResourceViewResolver,后台报错了:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name “”viewResolver”” defined in file [E:\Software\apache-tomcat-7.0.12\webapps\cms\WEB-INF\classes\spring\springmvc-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property “”exposeSpringMacroHelpers”” of bean class [org.springframework.web.servlet.view.InternalResourceViewResolver]: Bean property “”exposeSpringMacroHelpers”” is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1423)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1189)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1103)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1010)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4935)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5262)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5257)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property “”exposeSpringMacroHelpers”” of bean class [org.springframework.web.servlet.view.InternalResourceViewResolver]: Bean property “”exposeSpringMacroHelpers”” is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1042)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:902)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1420)
… 28 more
2014-8-25 17:58:58 org.apache.catalina.core.ApplicationContext log

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
引用 9 楼 shijing266 的回复:
Quote: 引用 7 楼 dingding5060 的回复:
Quote: 引用 4 楼 dingding5060 的回复:
Quote: 引用 3 楼 shijing266 的回复:

建议看看完整的FreeMarkerViewResolver配置   

http://liuxlyard.iteye.com/blog/1156081

行,我试试看!

按照这个例子,还是:

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符

加入代码如下:


<!-- 定义FreeMarker视图解析器与属性配置 -->
	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
		<property name="cache" value="true" />
		<property name="prefix" value="" />
		<property name="suffix" value=".ftl" />
		<property name="viewClass"
			value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
		<property name="exposeSpringMacroHelpers" value="true" />
		<property name="exposeRequestAttributes" value="true" />
		<property name="exposeSessionAttributes" value="true" />
		<property name="requestContextAttribute" value="rc" />
		<property name="contentType" value="text/html;charset=UTF-8" />
	</bean>

	<bean id="freemarkerConfig"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<property name="templateLoaderPath" value="/WEB-INF/view/" />
		<property name="freemarkerSettings">
			<props>
				<prop key="template_update_delay">5</prop>
				<prop key="defaultEncoding">UTF-8</prop>
				<prop key="url_escaping_charset">UTF-8</prop>
				<prop key="locale">zh_CN</prop>
				<prop key="boolean_format">true,false</prop>
				<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
				<prop key="time_format">HH:mm:ss</prop>
				<prop key="number_format">0.######</prop>
				<prop key="whitespace_stripping">true</prop>
			</props>
		</property>
	</bean> 

index.ftl代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   
 "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
    <head>  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
        <title>${title}</title>  
    </head>  
    <body>  
        ${name}  
    </body>  
</html> 

恩,改了配置没?  现在可以了么?  还是原来的? 现在用的是jsp还是html

页面时index.ftl,配置前缀匹配改为.ftl了!不知道改得对不对!

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
90分
下班了,回去帮你看
Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
引用 12 楼 shijing266 的回复:

下班了,回去帮你看

恩恩,非常感谢!这个问题纠结了好久,网上找的资源都没有这样的情况;唯一找到一个说是缺少一个依赖包javarebel.jar,但是下载了导入没用!

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
引用 13 楼 dingding5060 的回复:
Quote: 引用 12 楼 shijing266 的回复:

下班了,回去帮你看

恩恩,非常感谢!这个问题纠结了好久,网上找的资源都没有这样的情况;唯一找到一个说是缺少一个依赖包javarebel.jar,但是下载了导入没用!

对了,忘了说了,你页头有没有导入下面这几个

<%@ page language=”java” pageEncoding=”UTF-8″%>
<%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core”%>
<c:set var=”ctx” value=”${pageContext.request.contextPath}” />

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
引用 14 楼 shijing266 的回复:
Quote: 引用 13 楼 dingding5060 的回复:
Quote: 引用 12 楼 shijing266 的回复:

下班了,回去帮你看

恩恩,非常感谢!这个问题纠结了好久,网上找的资源都没有这样的情况;唯一找到一个说是缺少一个依赖包javarebel.jar,但是下载了导入没用!

对了,忘了说了,你页头有没有导入下面这几个

<%@ page language=”java” pageEncoding=”UTF-8″%>
<%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core”%>
<c:set var=”ctx” value=”${pageContext.request.contextPath}” />

<%@ 的引用应该是针对jsp的吧? 页面中也没有用到jstl标签喔。加入你的代码后,还是一样的!

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
已经解决了,是我在spring配置文件中配置了2个ViewResolver,冲突了,但是启动没有报错,所以导致的,多谢各位回复!结贴
Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
学习下,遇到同样的问题。
Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
对了,忘了说了,你页头有没有导入下面这几个

<%@ page language=”java” pageEncoding=”UTF-8″%>
<%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core”%>
<c:set var=”ctx” value=”${pageContext.request.contextPath}” />

<%@ 的引用应该是针对jsp的吧? 页面中也没有用到jstl标签喔。加入你的代码后,还是一样的!

sorry,昨天没看清, 现在找了两个应该有用的。  一个还是修改视图解析器,一个是添加strust2标签配置

这是视图的
http://zhidao.baidu.com/question/1754707505480347668.html?qbl=relate_question_3&word=ftl%20%B1%EA%C7%A9%C3%BB%C6%F0%D7%F7%D3%C3

这是struts2标签的
http://it.oyksoft.com/post/5733/

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
引用 16 楼 dingding5060 的回复:

已经解决了,是我在spring配置文件中配置了2个ViewResolver,冲突了,但是启动没有报错,所以导致的,多谢各位回复!结贴

我去…

Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
在web.xml加上这段试试    
<filter>
   <filter-name>freemarkerFilter</filter-name>
   <filter-class>com.uws.core.freemarker.FreemarkerFilter</filter-class>
  </filter>
  <filter-mapping>
   <filter-name>freemarkerFilter</filter-name>
   <url-pattern>*.ftl</url-pattern>
   <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
  </filter-mapping>

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Spring mvc整合Freemarker后,前台标签取值,直接显示标签字符
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!