Struts2 uses cookie to implement automatic login using filter to read context method

HttpSession session = request.getSession(); 

        IUserDao ud=(IUserDao)this.getObjectFromApplication(session.getServletContext(), "IUserDao");

After execution, ud can directly call the method in it

 

/** 

   * Get an instance of the Spring container through WebApplicationContextUtils. Returns an instance of the bean based on the bean's name. 

   * @param servletContext : ServletContext context. 

   * @param beanName : The name of the bean in the Spring container to be obtained. 

   * @return returns an instance of the Bean. 

   */  

  private Object getObjectFromApplication(ServletContext servletContext,String beanName){  

      //Get an instance of the Spring container through WebApplicationContextUtils.  

      ApplicationContext application=WebApplicationContextUtils.getWebApplicationContext(servletContext);  

      //Return the instance of Bean.  

      return application.getBean(beanName);  

  } 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326906438&siteId=291194637