Action访问ServletAPI

Action访问ServletAPI

  • 取得Map类型的request、session、application
    • 属性
      • java request = (Map)ActionContext.getContext().get("request");
      • java session = (Map)Action.Context.getContext().getSession();
      • java application = (Map)ActionContext.getContext().getApplication();
    • IoC(Inversion Of Control, 控制反转):RequestAware、SessionAware、ApplicationAware
  • 取得真实类型的HttpServletRequest、HttpSession、ServletContext

    • ServletActionContext.getContext()
    private HttpServletRequest;
    private HttpSession;
    private ServletContext application;
    public AccessServletAPIAction3(){
        this.request = ServletActionContext.getRequest();
        this.session = this.request.getSession();
        this.application = ServletActionContext.getServletContext();
    }
    • ServletRequestAware、SerlvetResponseAware、ServletContextAware;似乎也是控制反转

你可能感兴趣的:(Struts2)