zoukankan      html  css  js  c++  java
  • 在SpringMVC中获取request对象

    1.注解法

    Java代码  收藏代码
    1. @Autowired  
    2. private  HttpServletRequest request;  

    2. 在web.xml中配置一个监听

    Xml代码  收藏代码
    1. <listener>    
    2.         <listener-class>    
    3.             org.springframework.web.context.request.RequestContextListener    
    4.         </listener-class>    
    5. </listener>    

    之后在程序里可以用

    Java代码  收藏代码
    1. HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();    

     3.直接在参数中引入

    Java代码  收藏代码
    1. public String hello(HttpServletRequest request,HttpServletResponse response)  

    如何在Struts2中获取request对象

    Java代码  收藏代码
    1. HttpServletRequest request = ServletActionContext.getRequest();  
  • 相关阅读:
    请求headers处理
    requests模块
    urllib3
    urllib
    百度AI搜索引擎
    CSS层叠样式表--使用
    学习requests_html
    聚合新闻头条
    爬虫工程师的月薪如何?
    Linux日志系统
  • 原文地址:https://www.cnblogs.com/huhuixin/p/5948390.html
Copyright © 2011-2022 走看看