java在方法中获取request对象

在spring的普通类中:

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

request.getSession();

在Struts的普通类中:

HttpServletRequest request = ServletActionContext.getRequest();

request.getSession();

HttpServletResponse response =ServletActionContext.getResponse();

转载于:https://www.cnblogs.com/java-xz/p/10672115.html

你可能感兴趣的:(java)