Skip to content

Instantly share code, notes, and snippets.

@yanhua365
Created September 18, 2014 09:42
Show Gist options
  • Save yanhua365/ad03506e27f344ec2505 to your computer and use it in GitHub Desktop.
Save yanhua365/ad03506e27f344ec2505 to your computer and use it in GitHub Desktop.
Spring配置RequestContextListener可以在任何地方得到HttpRequest对象。
//在任意的class下通过以下方法获取到HttpServletRequest
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
<!-- WEB.XML中配置相关的监听机制 -->
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment