Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1901064
  • 博文数量: 606
  • 博客积分: 9991
  • 博客等级: 中将
  • 技术积分: 5725
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-17 19:07
文章分类

全部博文(606)

文章存档

2011年(10)

2010年(67)

2009年(155)

2008年(386)

分类: Java

2009-08-24 15:48:45

struts2 Action中获取request, response对象的方法

struts2 Action中获取request, response对象的方法  

  1. ActionContext ctx = ActionContext.getContext();       
  2.       
  3.   HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);       
  4.       
  5.   HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);       
  6.         
  7.   //ServletActionContext.APPLICATION;       
  8.   //ServletActionContext.SESSION;       
  9.   //ServletActionContext.PAGE_CONTEXT;      

 java 代码

 1private final String getClientAddress(HttpServletRequest request) {    
 2
 3    String address = request.getHeader("X-Forwarded-For");    
 4
 5    if (address != null && StringUtil.isIPAddress(address)) {    
 6
 7        return address;    
 8
 9    }
    
10
11    return request.getRemoteAddr();    
12
13}
   
14
阅读(5526) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~