耦合方式即通过原生的API进行流转。
与前面的解耦合对比,命名上多了一个servlet
处理类也是两种方式:
public class TestServletActionContext { public String execute() { HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = ServletActionContext.getRequest().getSession(); ServletContext servletContext = ServletActionContext.getServletContext(); return "success"; } }
方式二,采用的是实现接口方式
public class TestAwareServletAction implements ServletContextAware,ServletRequestAware{ @Override public void setServletRequest(HttpServletRequest request) { // TODO Auto-generated method stub } @Override public void setServletContext(ServletContext context) { // TODO Auto-generated method stub } }