「Struts2」インターセプター(interceptor)でHttpServletRequestを取得する方法

説明
1.ActionContext
Actionクラスからの変数を受け取ります
2.ServletActionContext.HTTP_REQUEST
HTTPリクエストオブジェクトの定数
Javaコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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
}

 

Struts2

Posted by arkgame