
楼主解决了?我也遇到了,网上暂时没搜到解决办法,我换做Spring 32版本测试可以正常使用,不知道是不是Spring4中有什么变化。
我在stackOverflow上的提问:>
默认地,表单数据会编码为 "application/x->
/
封装Spring ApplicationConext引用, 方便工程通过API获取bean实例
@author bjb-336
/
@Component
public class SpringContextWrapper implements ApplicationContextAware{
private static ApplicationContext appContext;
/
根据beanName 获取bean实例
@param beanName
@return
/
public static Object getBean(String beanName){
Object obj = null;
if (null != appContext){
obj = appContextgetBean(beanName);
}
return obj;
}
/
根据bean名称和类型进行获取Bean的实例
@param beanName
@param clsType
@return
/
public static <T> T getBean(String beanName, Class<T> clsType){
T obj = null;
if (null != appContext){
obj = appContextgetBean(beanName, clsType);
}
return obj;
}
/
根据类型进行获取Bean的实例
@param clsType
@return
/
public static <T> T getBean(Class<T> clsType){
T obj = null;
if (null != appContext){
obj = appContextgetBean(clsType);
}
return obj;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SpringContextWrapperappContext = applicationContext;
}
}
先附上一个SiteMesh3+FreeMarker+SpringMVC例子/adaikiss/sitemesh3_freemarker_springmvczip下载后解压,本地环境变量要有MAVEN,CMD进入工程目录直接运行mvnjetty:run昨天花了一天时间来跟踪调试springmvc,freemarker,sitemesh3,终于弄明白了大概的原理,最后解决了sitemesh中文(UTF-8)乱码,ftl装饰页不被渲染的问题。sitemesh3是通过一个filter来对response进行拦截处理,在response提交之前,它会把response流里的数据备份起来,清空流,然后用requestgetRequestDispatcher(装饰页URI)forward()来取得渲染后的装饰页,然后再把装饰页里的标签替换成之前备份的对应内容。也就是说sitemesh不关心你的页面是如何生成的,它只是将两者拼接起来,不管你用的是JSP,Volocity,FreeMarker还是SpringMVC,Struts,wicket。这样一来你就可以灵活地控制页面的生成方式。你可以把sitemesh3当成一个中间浏览器,他使用用户浏览器发送过来的request对象发送了两次(或以上)请求,第一次是原来的请求,第二次是对装饰页面的请求,然后把这两个请求结果拼接起来返回给用户浏览器。看到这里,装饰页如果是FTL就不被渲染的问题也就有了解决方法了。只要自己写一个过滤器对ftl的请求用freemarker渲染一遍就可以了。由于我使用的是springmvc+freemarker,因此我直接拿springmvc来渲染FTL文件了,这样可以像被装饰页一样方便地使用spring的宏和其他一些对象。下面是我的filter复制代码publicclassFreemarkerFilterimplementsFilter{privateLocalelocale;@Overridepublicvoidinit(FilterConfigfilterConfig)throwsServletException{StringlocaleStr=filterConfiggetInitParameter("locale");if(StringUtilsisNotBlank(localeStr)){locale=newLocale(localeStr);}else{locale=LocalegetDefault();}}@OverridepublicvoiddoFilter(ServletRequestrequest,ServletResponseresponse,FilterChainchain)throwsIOException,ServletException{try{>
以上就是关于我在搭建spring mvc和dwr框架的时候遇到了一个问题。全部的内容,包括:我在搭建spring mvc和dwr框架的时候遇到了一个问题。、用spring mvc做,用post方式提交后台获取不到参数值,为什么用get方式就可以、工具类中怎么注入service,spring mvc +mybatiss等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)