大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專(zhuān)注Java教育14年 全國(guó)咨詢(xún)/投訴熱線:400-8080-105
動(dòng)力節(jié)點(diǎn)LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁(yè) hot資訊 SpringMVC獲取request的方式

SpringMVC獲取request的方式

更新時(shí)間:2022-03-25 09:29:47 來(lái)源:動(dòng)力節(jié)點(diǎn) 瀏覽2179次

SpringMVC獲取request的方式有哪些?小編來(lái)告訴大家。

1.最簡(jiǎn)單的方式(注解法)

@Autowired
private  HttpServletRequest request;

2.最麻煩的方法

(1)在web.xml中配置一個(gè)監(jiān)聽(tīng)

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

(2)之后在程序里可以用

HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();  

原理

RequestContextListener實(shí)現(xiàn)了 ServletRequestListener ,在其覆蓋的requestInitialized(ServletRequestEvent requestEvent)方法中,將request最終設(shè)置到了RequestContextHolder中.

public class RequestContextListener implements ServletRequestListener {
    private static final String REQUEST_ATTRIBUTES_ATTRIBUTE =
            RequestContextListener.class.getName() + ".REQUEST_ATTRIBUTES";
    @Override
    public void requestInitialized(ServletRequestEvent requestEvent) {
        if (!(requestEvent.getServletRequest() instanceof HttpServletRequest)) {
            throw new IllegalArgumentException(
                    "Request is not an HttpServletRequest: " + requestEvent.getServletRequest());
        }
        HttpServletRequest request = (HttpServletRequest) requestEvent.getServletRequest();//從事件對(duì)象中獲取request對(duì)象
        ServletRequestAttributes attributes = new ServletRequestAttributes(request);//將request設(shè)置到servletRequestAttributes中
        request.setAttribute(REQUEST_ATTRIBUTES_ATTRIBUTE, attributes);//反過(guò)來(lái)將servletRequestAttributes設(shè)置到request中
        LocaleContextHolder.setLocale(request.getLocale());
        RequestContextHolder.setRequestAttributes(attributes);//再將servletRequestAttributes設(shè)置到requestContextHolder中
    }

3.最直接的方法

public String hello(HttpServletRequest request,HttpServletResponse response) 

通過(guò)以上介紹相信大家對(duì)SpringMVC獲取request的方式已經(jīng)有所了解,大家如果想了解更多相關(guān)知識(shí),不妨來(lái)關(guān)注一下動(dòng)力節(jié)點(diǎn)的Java在線學(xué)習(xí),里面的課程內(nèi)容豐富,從入門(mén)到精通,很適合零基礎(chǔ)的小伙伴學(xué)習(xí),希望對(duì)大家能夠有所幫助。

提交申請(qǐng)后,顧問(wèn)老師會(huì)電話與您溝通安排學(xué)習(xí)

  • 全國(guó)校區(qū) 2025-04-24 搶座中
  • 全國(guó)校區(qū) 2025-05-15 搶座中
  • 全國(guó)校區(qū) 2025-06-05 搶座中
  • 全國(guó)校區(qū) 2025-06-26 搶座中
免費(fèi)課程推薦 >>
技術(shù)文檔推薦 >>
主站蜘蛛池模板: 国内精品免费一区二区观看 | 青青久久精品国产免费看 | 九九色综合 | 欧美wwwxxx| 中文字幕免费观看视频 | 国产成人一区二区三区在线视频 | 亚洲综合伊人色一区 | 久久婷婷综合在线视频观看6 | 国产一级一片免费播放 | 9久9久热精品视频在线观看 | 久久99精品国产 | 毛片一级在线 | 四虎国产精品成人永久免费影视 | 欧美日韩国产片 | 国产午夜亚洲精品不卡福利 | 在线播放精品视频 | 在线观看 亚洲 | 奇米影音先锋 | 日本欧美中文字幕 | 涩涩免费播放观看在线视频 | 久久精品中文字幕一区 | 一级久久 | 亚洲一级黄色 | 亚洲一级理论片 | 四虎国产精品一区二区 | 亚洲韩国日本一级二级r级 亚洲韩精品欧美一区二区三区 | 国产欧美一区二区另类精品 | 亚洲国产精品久久卡一 | 日日噜噜夜夜狠狠tv视频免费 | 中文久久 | 天天干天天拍天天射天天添天天爱 | 热99这里有精品综合久久 | 大尺度视频网站久久久久久久久 | 国产成人精品高清在线观看99 | 久99久精品视频免费观看v | 极品粉嫩粉嫩福利视频在线 | 你懂的91 | 精品免费福利视频 | 精品成人一区二区三区免费视频 | 欧美性生活一级 | 成人性生免费视频 |