1
2
3
4
5
|
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
ServletContext servletContext = ServletActionContext.getServletContext();
PageContext pageContext = ServletActionContext.getPageContext();
HttpSession session = ServletActionContext.getRequest().getSession();
|
1
2
3
4
5
6
7
8
9
10
11
12
|
package
org.apache.struts2.util;
import
javax.servlet.ServletContext;
/**
* For components that have a dependence on the Servlet context.
*/
public
interface
ServletContextAware {
public
void
setServletContext(ServletContext context);
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package
org.apache.struts2.interceptor;
import
javax.servlet.http.HttpServletRequest;
/**
* All Actions that want to have access to the servlet request object must implement this interface.<p>
* <p/>
* This interface is only relevant if the Action is used in a servlet environment. <p>
* <p/>
* Note that using this interface makes the Action tied to a servlet environment, so it should be
* avoided if possible since things like unit testing will become more difficult.
*
*/
public
interface
ServletRequestAware {
/**
* Sets the HTTP request object in implementing classes.
*
* @param request the HTTP request.
*/
public
void
setServletRequest(HttpServletRequest request);
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package
org.apache.struts2.interceptor;
import
javax.servlet.http.HttpServletResponse;
/**
* All Actions that want to have access to the servlet response object must implement this interface.<p>
* <p/>
* This interface is only relevant if the Action is used in a servlet environment.<p>
* <p/>
* Note that using this interface makes the Action tied to a servlet environment, so it should be
* avoided if possible since things like unit testing will become more difficult.
*
*/
public
interface
ServletResponseAware {
/**
* Sets the HTTP response object in implementing classes.
*
* @param response the HTTP response.
*/
public
void
setServletResponse(HttpServletResponse response);
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package
org.apache.struts2.interceptor;
import
java.util.Map;
/**
* Actions that want access to the user's HTTP session attributes should implement this interface.<p>
* <p/>
* This will give them access to a Map where they can put objects that can be made available
* to subsequent requests.<p/>
* <p/>
* Typical uses may be cached user data such as name, or a shopping cart.
*
*/
public
interface
SessionAware {
/**
* Sets the Map of session attributes in the implementing class.
*
* @param session a Map of HTTP session attribute name/value pairs.
*/
public
void
setSession(Map<String,Object> session);
}
|