Java tutorial
/** The MIT License (MIT) * Copyright (c) 2015 * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.rxx.base.interceptor; import com.mingsoft.base.constant.Const; import com.mingsoft.base.constant.SessionConst; import com.mingsoft.util.StringUtil; import org.apache.log4j.Logger; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * actionbasebasepath * @author QQ:78750478 * @version * 100-000-000<br/> * 2012-03-15<br/> * <br/> */ public class ActionInterceptor extends HandlerInterceptorAdapter { protected Logger logger = Logger.getLogger(this.getClass()); private static String BASE = "base"; private static String BASE_PATH = "basePath"; private static String MODEL_ID = "modelId"; private static String BASE_URL = "baseUrl"; public static boolean IS_WINDOWS = false; static { if (System.getProperty("os.name").toLowerCase().indexOf("windows") > 0) { IS_WINDOWS = true; } } /** * action,basebasepath * @param request HttpServletRequest * @param response HttpServletResponse * @param handler * @throws Exception * @return true */ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String modelId = request.getParameter(MODEL_ID); // if (StringUtil.isInteger(modelId)) { request.getSession().setAttribute(SessionConst.MODEL_ID_SESSION.toString(), modelId); request.getSession().setAttribute(SessionConst.MODEL_TITLE_SESSION.toString(), request.getParameter("modelTitle")); } request.setAttribute(BASE, Const.BASE); request.setAttribute(BASE_PATH, request.getScheme() + "://" + request.getServerName() + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort()) + Const.BASE); request.setAttribute(BASE_URL, request.getScheme() + "://" + request.getServerName() + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort()) + request.getContextPath() + request.getServletPath() + (request.getQueryString() == null ? "" : "?" + request.getQueryString())); return true; } }