「Struts2」インターセプター(interceptor)でHttpServletRequestを取得する方法
説明
1.ActionContext
Actionクラスからの変数を受け取ります
2.ServletActionContext.HTTP_REQUEST
HTTPリクエストオブジェクトの定数
Javaコード
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext actionContext= ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest)actionContext
.get(ServletActionContext.HTTP_REQUEST);
String parameterA=request.getParameter("devId");
String parameterB=request.getParameter("age");
//some code
}
public String intercept(ActionInvocation invocation) throws Exception {
ActionContext actionContext= ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest)actionContext
.get(ServletActionContext.HTTP_REQUEST);
String parameterA=request.getParameter("devId");
String parameterB=request.getParameter("age");
//some code
}
public String intercept(ActionInvocation invocation) throws Exception { ActionContext actionContext= ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)actionContext .get(ServletActionContext.HTTP_REQUEST); String parameterA=request.getParameter("devId"); String parameterB=request.getParameter("age"); //some code }