Struts2入門–ServletRequestAwareでrequest、sessionオブジェクトを取得する

Actionコード:
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.ActionSupport;

public class Logincft4Action extends ActionSupport
implements ServletRequestAware , ServletContextAware{
private HttpServletRequest request;
private HttpSession session;
private ServletContext application;

@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
this.request.setAttribute(“attribute", “request value servlet IoC “);
this.session = this.request.getSession();
this.session.setAttribute(“attribute", “session value servlet IoC “);
this.application.setAttribute(“attribute", “application value servlet IoC “);
return SUCCESS;
}

@Override
public void setServletRequest(HttpServletRequest arg0) {
// TODO Auto-generated method stub
this.request = arg0;
}

@Override
public void setServletContext(ServletContext arg0) {
// TODO Auto-generated method stub
this.application = arg0;
}
}

Java

Posted by arkgame