I'm porting a dynamic web project to Struts2 and I gotta convert a many servlets to Struts2 actions. I want to use the ServletRequestAware, ServletResponseAware and SessionAware interfaces and keep most of the code unchanged. Please take a look at BaseAction.java class which I found by GOOGLin'. I want to use this so that i can make other actions to simply extend the BaseAction.
BaseAction.java
public abstract class BaseAction extends ActionSupport implements SessionAware, ServletRequestAware,ServletResponseAware, ServletContextAware{
private static final long serialVersionUID = 1L;
protected Map session;
protected HttpServletRequest request;
protected HttpServletResponse response;
public String execute() throws Exception {
return doExecute();
}
protected abstract String doExecute() throws Exception;
public Map getSession() {
return session;
}
public void setSession(Map sess) {
this.session = sess;
}
public HttpServletRequest getServletRequest() {
return request;
}
public void setServletRequest(HttpServletRequest req){
this.request = req;
}
public HttpServletResponse getServletResponse() {
return response;
}
public void setServletResponse(HttpServletResponse resp) {
this.response = resp;
}
}
Now Suppose I have a servlet like following: Servlet.java
public class Servlet extends HttpServlet
{
private static Logger log = Logger.getLogger(Servlet.class);
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException
{
HttpSession session=request.getSession();
Bean bean= new Bean();
bean.setName(request.getParameter("xxx"));
session.setAttribute("bean");
response.sendRedirect("login.jsp");
}
}
Can someone write an action class extending the BaseAction equivalent to the Servlet? Thanks in advance.