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 java.util.List; 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; /** * ZbVwv?peB???B * * <p> * Bean`t@CwL?[Xg?A * ZbV??L?[???s?B<br> * </p> * * <p> * J??A?<action>vf * parameter?wAhXtH??[h?A * parameter?K?{?B * ?ALBean`t@Cystruts-config.xml * ??B * </p> * <p> * <strong>Bean`t@CClearSessionAction?</strong> * <code><pre> * <bean name="/clearSessionAction" scope="singleton" * class="jp.terasoluna.fw.web.struts.actions.ClearSessionAction"> * <strong><property name="clearSessionKeys"> * <list> * <value>userAddress</value> * <value>userPhoneNo</value> * <value>sampleSession</value> * </list> * </property></strong> * </bean> * </pre></code> * </p> * <p> * <strong>struts-config.xml?</strong> * <code><pre> * <action path="/clearSessionAction" * name="_sampleForm" * scope="session" * parameter="/sessionCleared.do"> * </action> * </pre></code> * ?L??AANVpX"/clearSessionAction" * ?s?AclearSessionKeysv?peB???L?[ * ?A?AuserAddress?AuserPhoneNo?AsampleSession * 3ZbVL?[Q?ZbV????B<br> * ?ZbVj???ALogoffActionQ??B * </p> * * @see jp.terasoluna.fw.web.struts.actions.LogoffAction * */ public class ClearSessionAction extends ActionEx { /** * ?ONX?B */ private static Log log = LogFactory.getLog(ClearSessionAction.class); /** * G?[y?[W?i404?jJsG?[R?[h?B */ private static final String FORWARD_ERRORPAGE_ERROR = "error.forward.errorpage"; /** * ZbV??L?[Xg?B */ private List clearSessionKeys = null; /** * ZbV??L?[Xg??B * * @param clearSessionKeys ZbV??L?[Xg */ public void setClearSessionKeys(List clearSessionKeys) { this.clearSessionKeys = clearSessionKeys; } /** * ZbVNA?s?AtH??[h?B * <p> * ???L?[P???A * J??p?A???I?B * </p> * @param mapping ANV}bsO * @param form ANVtH?[ * @param request <code>HTTP</code>NGXg * @param response <code>HTTP</code>X|X * @return J?? */ @Override public ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); if (clearSessionKeys != null) { for (int cnt = 0; cnt < clearSessionKeys.size(); cnt++) { String sKey = (String) clearSessionKeys.get(cnt); if (log.isDebugEnabled()) { log.debug("removing [" + sKey + "] from HttpSession"); } //ZbV???s session.removeAttribute(sKey); } } // p??[^??itH??[h??j String path = mapping.getParameter(); if (path == null) { // p??[^?????A(404)G?[p try { response.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; } }