1: 使用spring freemarker 3 起的话,可以使用
@Autowired
private HttpServletRequest request;2:
使用: ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
在web.xml添加监听器:
<span style="white-space:pre"></span><pre name="code" class="html"><span style="white-space:pre"> </span><listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>

本文介绍在SpringFreemarker环境下两种获取HttpServletRequest的方法:一是直接通过@Autowired注解注入;二是利用RequestContextHolder结合RequestContextListener监听器实现。适用于需要在模板引擎中访问HTTP请求上下文的场景。
1858

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



