springmvc中获得HttpServletRequest request方法(org.springframework.web.context.request.RequestContextList)
2013-01-06 14:42
519 查看
在Spring2.0中除了以前的Singleton和Prototype外又加入了三个新的web作用域,分别为request、session和global
session,它们的含义和用法请大家参考Spring官方手册的相关章节。如果你想让你的容器里的某个bean拥有其中某种新的web作用域,除了在bean级上配置相应的scope属性,还必须在容器级做一个额外的初始化配置。即在web应用的XML声明文件web.xml中增加下述ContextListener:
1 <web-app>
2
3 <listener>
4 <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
5 </listener>
6
7 </web-app>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
在web.xml中配置一个监听
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
之后就可以在程序使用了
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
session,它们的含义和用法请大家参考Spring官方手册的相关章节。如果你想让你的容器里的某个bean拥有其中某种新的web作用域,除了在bean级上配置相应的scope属性,还必须在容器级做一个额外的初始化配置。即在web应用的XML声明文件web.xml中增加下述ContextListener:
1 <web-app>
2
3 <listener>
4 <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
5 </listener>
6
7 </web-app>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
在web.xml中配置一个监听
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
之后就可以在程序使用了
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
相关文章推荐
- springMVC:org.springframework.web.servlet.PageNotFound.handleHttpRequestMethodNotSupported Request method 'POST' not supported
- java报错-->Error creating bean with name 'org.springframework.web.servlet.resource.ResourceHttpRequest
- [org.springframework.web.servlet.PageNotFound] - No mapping found for HTTP request with URI
- org.springframework.web.se rvlet.DispatcherServlet.noHandlerFound No mapping found for HTTP request
- 用kindeditor 报:org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
- cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
- org.springframework.web.servlet.PageNotFound noHandlerFound 警告: No mapping found for HTTP request w
- org.springframework.web.servlet.PageNotFound]-[WARN] No mapping found for HTTP request with URI [/re
- .ShiroHttpServletRequest cannot be cast to org.springframework.web.multipart.MultipartHttpServletReq
- cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
- [org.springframework.web.servlet.PageNotFound] - No mapping found for HTTP request with URI [/ssm/us
- org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupportedWARNING: Request met
- org.springframework.web.util.NestedServletException: Request processing failed; nested exception is
- IDEA调试SpringMvc项目时,出错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener,解决办法
- SpringMVC上传图片总结(1)-Web Uploader--常规方法进行图片上传,使用了MultipartFile、MultipartHttpServletRequest
- 解决JBoss7部署应用时Not installing optional component org.springframework.web.context.request.async.Standar
- TOM启动报错:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListe
- idea调试SpringMvc, 出现:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderL
- springCloud:"exception":"org.springframework.web.bind.MissingServletRequestParameterException","mess