logoutaction.java

来自「网上商店 新增功能: 1」· Java 代码 · 共 39 行

JAVA
39
字号
package netstore.security;

import java.util.Locale;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import netstore.businessobjects.Customer;
import netstore.framework.exceptions.BaseException;
import netstore.framework.SessionContainer;
import netstore.framework.NetstoreBaseAction;
import netstore.framework.util.IConstants;
import netstore.service.INetstoreService;

/**
 * This action is called when a user checks out of the Netstore
 * application.
 */
public class LogoutAction extends NetstoreBaseAction {
  public ActionForward execute( ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response )
    throws Exception {

    HttpSession session = request.getSession(false);
    // Make sure the user has a valid session
    if(session != null) {
      if(getSessionContainer(request) != null) {
        // Login through the security service
        INetstoreService serviceImpl = this.getNetstoreService();
        serviceImpl.logout( getSessionContainer(request).getCustomer().getEmail());
        getSessionContainer(request).cleanUp();
      }
      //全部session失效
      session.invalidate();
    }
    return mapping.findForward( IConstants.SUCCESS_KEY );
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?