1.最简单的方式(注解法)

 @Autowired  private  HttpServletRequest request;

2.最麻烦
a. 在web.xml中配置一个监听

<listener>  <listener-class>  org.springframework.web.context.request.RequestContextListener  </listener-class>
</listener>

b.之后在程序里可以用

//request:
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
//request:
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
HttpServletRequest request = servletRequestAttributes.getRequest();
//response:
ServletWebRequest servletWebRequest = (ServletWebRequest) RequestContextHolder.getRequestAttributes();
HttpServletResponse response= servletWebRequest.getResponse();

3.最直接的方法

public String hello(HttpServletRequest request,HttpServletResponse response)

4.方法里获得

HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

spring获得servletContext

//servletContext:
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext servletContext = webApplicationContext.getServletContext();

Struts2中获取request对象

HttpServletRequest request = ServletActionContext.getRequest();

springMVC中获取request 对象相关推荐

  1. springmvc中获取request对象,加载biz(service)的方法

    获取request对象: 首先配置web.xml文件--> [html] view plaincopy <listener> <listener-class> org.s ...

  2. java定时器任务中获取request对象 @Scheduled 获取request 对象 quartz中获取request对象

    java定时器任务中获取request对象 @Scheduled 获取request 对象 quartz中获取request对象 一.问题描述 1.在java定时任务中,使用 @Scheduled 注 ...

  3. spring aspect通知中获取request对象

    注:aop = aspect = 切面 在aspect 中一般是做: 事务控制.日志.权限控制 等等,这些场景. 在aop切面类中,直接使用ServletActionContext.getReques ...

  4. php怎么取request,PHP-如何在Guzzle中获取Request对象?

    我需要使用Guzzle检查数据库中的很多项目.例如,项目数量为2000-5000.将其全部加载到单个数组中太多了,因此我想将其分成多个块:SELECT * FROM items LIMIT100.当最 ...

  5. SpringCloud工作笔记039---spring cloud、javaweb中获取request对象的几种方法

    JAVA技术交流QQ群:170933152 这里我用的第二种,记录一下, 现在项目中,是微服务架构,做权限架构设计时,我通过request.getParemeter获取一个systype,来区分不同的 ...

  6. java获取当前request_java如何在一个普通的类中获取request对象

    展开全部 你是指你的 web 项目中使用到一个工具性的类,它的形参中没有 HttpRequest 或 HttpSession 参数62616964757a686964616fe4b893e5b19e3 ...

  7. Spring获取request对象的几种方式

    参考文章: 在SpringMVC中获取request对象的几种方式 Springboot获取request和response 使用Springboot,我们很多时候直接使用@PathVariable. ...

  8. Spring学习总结(28)——Spring获取request对象的几种方法及线程安全性总结

    分享一个大神的人工智能教程.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到人工智能的队伍中来!点击浏览教程 前言 在使用Spring MVC开发Web系统时,经常需要在处理请求时使用reque ...

  9. Spring 中获取 request 的几种方法,及其线程安全性分析

    概述 在使用Spring MVC开发Web系统时,经常需要在处理请求时使用request对象,比如获取客户端ip地址.请求的url.header中的属性(如cookie.授权信息).body中的数据等 ...

最新文章

  1. R语言ggplot2可视化图像设置不同的字体实战
  2. BZOJ 1856: [Scoi2010]字符串 [Catalan数]
  3. 剑指offer三:从尾到头打印链表
  4. Matlab的内部常数
  5. Java 如何线程间通信,面试被问哭。。。
  6. cdn刷新api_闲话 CDN
  7. 常见的网上邻居访问问题
  8. NOIP模拟测试7「方程的解·visit」
  9. python 入门到实践期末考试常出现的考试内容_Python编程入门到实践—列表篇(一)...
  10. 如何实现一个php框架系列文章【2】实现类的自动加载
  11. 解决vs2005无法连接sql数据库问题
  12. UVA 624 CD (01背包 带路径)
  13. Rhel6服务器日志浅谈
  14. pacpng文件格式说明
  15. 计算机网络管理工程师证书考试试题,(信息化知识)国家信息化人才考试计算机网络工程师模拟试题.pdf...
  16. 【seeprettyface.com】数据集:模特/明星人脸数据集
  17. 数据致敬'总裁'-C罗
  18. A1094、A1004
  19. 木板切割最优matlab,矩形木板最优切割方案的设计与实现
  20. TCP与UDP的区别:

热门文章

  1. numpy实用技巧(二)
  2. 数学与编程——统计与编程(均匀分布仿真高斯分布)
  3. Python 机器学习——线性代数和矩阵运算:从matlab迁移到python
  4. left join 一对多只取一条_Python爬虫教程:验证码的爬取和识别详解
  5. python常问问题_Python新手在作用域方面经常容易碰到的问题
  6. 电脑win7语音怎么测试软件,win7话筒怎么测试 win7话筒测试方法【图文】
  7. python 生成器_python 生成器 - 刘江的python教程
  8. 用python画皮卡丘-教你用Python画一只属于自己的皮卡丘
  9. python必背入门代码-你们都是怎么学 Python 的?
  10. python是什么软件-python一般用什么软件