1. 程式人生 > >spring 獲取ServletContext物件 ,獲取HttpServletRequest物件

spring 獲取ServletContext物件 ,獲取HttpServletRequest物件

String rootPath = ContextLoader.getCurrentWebApplicationContext().getServletContext().getRealPath("/");

private HttpServletRequest getRequest() { 
        return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest(); 
    }