---
title: "struts2中获得request和session"
author: "lovezzy"
date: "2008-12-17T09:36:14Z"
tags: []
slug: "struts2-request-session"
draft: false
lastmod: "2008-12-17T09:37:34Z"
id: 295767
url: "https://lovezzy.iteye.com/blog/295767"
---

request:

Java代码 [![复制代码](http://zhykhs.iteye.com/images/icon_copy.gif)](http://zhykhs.iteye.com/admin/blogs/205858 "复制代码")

```
		ValueStack request = ActionContext.getContext().getValueStack();
		
		HttpServletRequest request = ServletActionContext.getRequest();
		
		HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
```

 

session:

Java代码 [![复制代码](http://zhykhs.iteye.com/images/icon_copy.gif)](http://zhykhs.iteye.com/admin/blogs/205858 "复制代码")

1. HttpSession session = ServletActionContext.getRequest().getSession();
2. HttpSession session = (HttpSession)ActionContext.getContext().get(ServletActionContext.SESSION);
3. Map map = (Map)ActionContext.getContext().getSession();