Java tutorial
/* * Copyright (c) 2007 NTT DATA Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package jp.terasoluna.fw.web.struts.actions; import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import jp.terasoluna.fw.exception.SystemException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; /** * ?OIt???sANV?B * * <p> * NX?A?HTTPZbV?A * struts-config.xml<action>vf * parameter?w?tH??[h?B * struts-config.xmlyBean`t@C?L?B * </p> * <p> * <strong>Bean`t@C?</strong> * <code><pre> * <bean name="/logoff" scope="prototype" * <strong>class="jp.terasoluna.fw.web.struts.actions.LogoffAction"</strong>> * </bean> * </pre></code> * </p> * <p> * <strong>struts-config.xml?</strong> * <code><pre> * <action path="/logoff" * name="_logonForm" * scope="session" * parameter="/foo.jsp"> * </action> * </pre></code> * ?OC???AUserValueObject?ABLogicQ??B * </p> * */ public class LogoffAction extends ActionEx { /** * ?ONX?B */ private static Log log = LogFactory.getLog(LogoffAction.class); /** * G?[y?[W?i404?jJsG?[R?[h?B */ private static final String FORWARD_ERRORPAGE_ERROR = "error.forward.errorpage"; /** * ?OIt???s?BHTTPZbV?A * parameter??J? * ANVtH??[hZbg?B * parameter?????A?i404?jG?[?B * * @param mapping ANV}bsO * @param form ANVtH?[ * @param req HTTPNGXg * @param res HTTPX|X * @return J?ANVtH??[h */ @Override public ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) { if (log.isDebugEnabled()) { log.debug("doExecute() called."); } // pZbV HttpSession session = req.getSession(false); if (session != null) { session.invalidate(); } // parameter??itH??[h??j String path = mapping.getParameter(); if (path == null) { // parameter?????A?i404?jG?[p try { res.sendError(HttpServletResponse.SC_NOT_FOUND); } catch (IOException e) { log.error("Error page(404) forwarding failed."); throw new SystemException(e, FORWARD_ERRORPAGE_ERROR); } return null; } // ANVtH??[h?? ActionForward retVal = new ActionForward(path); return retVal; } }