亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? resourceservlet.java

?? spring framework 2.5.4源代碼
?? JAVA
字號(hào):
/*
 * Copyright 2002-2008 the original author or authors.
 *
 * 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 org.springframework.web.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils;
import org.springframework.web.context.support.ServletContextResource;

/**
 * Simple servlet that can expose an internal resource, including a 
 * default URL if the specified resource is not found. An alternative,
 * for example, to trying and catching exceptions when using JSP include.
 *
 * <p>A further usage of this servlet is the ability to apply last-modified
 * timestamps to quasi-static resources (typically JSPs). This can happen
 * as bridge to parameter-specified resources, or as proxy for a specific
 * target resource (or a list of specific target resources to combine).
 *
 * <p>A typical usage would map a URL like "/ResourceServlet" onto an instance
 * of this servlet, and use the "JSP include" action to include this URL,
 * with the "resource" parameter indicating the actual target path in the WAR.
 *
 * <p>The <code>defaultUrl</code> property can be set to the internal
 * resource path of a default URL, to be rendered when the target resource
 * is not found or not specified in the first place.
 *
 * <p>The "resource" parameter and the <code>defaultUrl</code> property can
 * also specify a list of target resources to combine. Those resources will be
 * included one by one to build the response. If last-modified determination
 * is active, the newest timestamp among those files will be used.
 *
 * <p>The <code>allowedResources</code> property can be set to a URL
 * pattern of resources that should be available via this servlet.
 * If not set, any target resource can be requested, including resources
 * in the WEB-INF directory!
 *
 * <p>If using this servlet for direct access rather than via includes,
 * the <code>contentType</code> property should be specified to apply a
 * proper content type. Note that a content type header in the target JSP will
 * be ignored when including the resource via a RequestDispatcher include.
 *
 * <p>To apply last-modified timestamps for the target resource, set the
 * <code>applyLastModified</code> property to true. This servlet will then
 * return the file timestamp of the target resource as last-modified value,
 * falling back to the startup time of this servlet if not retrievable.
 *
 * <p>Note that applying the last-modified timestamp in the above fashion
 * just makes sense if the target resource does not generate content that
 * depends on the HttpSession or cookies; it is just allowed to evaluate
 * request parameters.
 *
 * <p>A typical case for such last-modified usage is a JSP that just makes
 * minimal usage of basic means like includes or message resolution to
 * build quasi-static content. Regenerating such content on every request
 * is unnecessary; it can be cached as long as the file hasn't changed.
 *
 * <p>Note that this servlet will apply the last-modified timestamp if you
 * tell it to do so: It's your decision whether the content of the target
 * resource can be cached in such a fashion. Typical use cases are helper
 * resources that are not fronted by a controller, like JavaScript files
 * that are generated by a JSP (without depending on the HttpSession).
 *
 * @author Juergen Hoeller
 * @author Rod Johnson
 * @see #setDefaultUrl
 * @see #setAllowedResources
 * @see #setApplyLastModified
 */
public class ResourceServlet extends HttpServletBean {

	/**
	 * Any number of these characters are considered delimiters
	 * between multiple resource paths in a single String value.
	 */
	public static final String RESOURCE_URL_DELIMITERS = ",; \t\n";

	/**
	 * Name of the parameter that must contain the actual resource path.
	 */
	public static final String RESOURCE_PARAM_NAME = "resource";


	private String defaultUrl;

	private String allowedResources;

	private String contentType;

	private boolean applyLastModified = false;

	private PathMatcher pathMatcher;

	private long startupTime;


	/**
	 * Set the URL within the current web application from which to
	 * include content if the requested path isn't found, or if none
	 * is specified in the first place.
	 * <p>If specifying multiple URLs, they will be included one by one
	 * to build the response. If last-modified determination is active,
	 * the newest timestamp among those files will be used.
	 * @see #setApplyLastModified
	 */
	public void setDefaultUrl(String defaultUrl) {
		this.defaultUrl = defaultUrl;
	}

	/**
	 * Set allowed resources as URL pattern, e.g. "/WEB-INF/res/*.jsp",
	 * The parameter can be any Ant-style pattern parsable by AntPathMatcher.
	 * @see org.springframework.util.AntPathMatcher
	 */
	public void setAllowedResources(String allowedResources) {
		this.allowedResources = allowedResources;
	}

	/**
	 * Set the content type of the target resource (typically a JSP).
	 * Default is none, which is appropriate when including resources.
	 * <p>For directly accessing resources, for example to leverage this
	 * servlet's last-modified support, specify a content type here.
	 * Note that a content type header in the target JSP will be ignored
	 * when including the resource via a RequestDispatcher include.
	 */
	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	/**
	 * Set whether to apply the file timestamp of the target resource
	 * as last-modified value. Default is "false".
	 * <p>This is mainly intended for JSP targets that don't generate
	 * session-specific or database-driven content: Such files can be
	 * cached by the browser as long as the last-modified timestamp
	 * of the JSP file doesn't change.
	 * <p>This will only work correctly with expanded WAR files that
	 * allow access to the file timestamps. Else, the startup time
	 * of this servlet is returned.
	 */
	public void setApplyLastModified(boolean applyLastModified) {
		this.applyLastModified = applyLastModified;
	}


	/**
	 * Remember the startup time, using no last-modified time before it.
	 */
	protected void initServletBean() {
		this.pathMatcher = getPathMatcher();
		this.startupTime = System.currentTimeMillis();
	}

	/**
	 * Return a PathMatcher to use for matching the "allowedResources" URL pattern.
	 * Default is AntPathMatcher.
	 * @see #setAllowedResources
	 * @see org.springframework.util.AntPathMatcher
	 */
	protected PathMatcher getPathMatcher() {
		return new AntPathMatcher();
	}


	/**
	 * Determine the URL of the target resource and include it.
	 * @see #determineResourceUrl
	 */
	protected final void doGet(HttpServletRequest request, HttpServletResponse response)
	    throws ServletException, IOException {

		// determine URL of resource to include
		String resourceUrl = determineResourceUrl(request);

		if (resourceUrl != null) {
			try {
				doInclude(request, response, resourceUrl);
			}
			catch (ServletException ex) {
				if (logger.isWarnEnabled()) {
					logger.warn("Failed to include content of resource [" + resourceUrl + "]", ex);
				}
				// Try including default URL if appropriate.
				if (!includeDefaultUrl(request, response)) {
					throw ex;
				}
			}
			catch (IOException ex) {
				if (logger.isWarnEnabled()) {
					logger.warn("Failed to include content of resource [" + resourceUrl + "]", ex);
				}
				// Try including default URL if appropriate.
				if (!includeDefaultUrl(request, response)) {
					throw ex;
				}
			}
		}

		// no resource URL specified -> try to include default URL.
		else if (!includeDefaultUrl(request, response)) {
			throw new ServletException("No target resource URL found for request");
		}
	}

	/**
	 * Determine the URL of the target resource of this request.
	 * <p>Default implementation returns the value of the "resource" parameter.
	 * Can be overridden in subclasses.
	 * @param request current HTTP request
	 * @return the URL of the target resource, or <code>null</code> if none found
	 * @see #RESOURCE_PARAM_NAME
	 */
	protected String determineResourceUrl(HttpServletRequest request) {
		return request.getParameter(RESOURCE_PARAM_NAME);
	}

	/**
	 * Include the specified default URL, if appropriate.
	 * @param request current HTTP request
	 * @param response current HTTP response
	 * @return whether a default URL was included
	 * @throws ServletException if thrown by the RequestDispatcher
	 * @throws IOException if thrown by the RequestDispatcher
	 */
	private boolean includeDefaultUrl(HttpServletRequest request, HttpServletResponse response)
	    throws ServletException, IOException {

		if (this.defaultUrl == null) {
			return false;
		}
		doInclude(request, response, this.defaultUrl);
		return true;
	}

	/**
	 * Include the specified resource via the RequestDispatcher.
	 * @param request current HTTP request
	 * @param response current HTTP response
	 * @param resourceUrl the URL of the target resource
	 * @throws ServletException if thrown by the RequestDispatcher
	 * @throws IOException if thrown by the RequestDispatcher
	 */
	private void doInclude(HttpServletRequest request, HttpServletResponse response, String resourceUrl)
	    throws ServletException, IOException {

		if (this.contentType != null) {
			response.setContentType(this.contentType);
		}
		String[] resourceUrls =
		    StringUtils.tokenizeToStringArray(resourceUrl, RESOURCE_URL_DELIMITERS);
		for (int i = 0; i < resourceUrls.length; i++) {
			// check whether URL matches allowed resources
			if (this.allowedResources != null && !this.pathMatcher.match(this.allowedResources, resourceUrls[i])) {
				throw new ServletException("Resource [" + resourceUrls[i] +
						"] does not match allowed pattern [" + this.allowedResources + "]");
			}
			if (logger.isDebugEnabled()) {
				logger.debug("Including resource [" + resourceUrls[i] + "]");
			}
			RequestDispatcher rd = request.getRequestDispatcher(resourceUrls[i]);
			rd.include(request, response);
		}
	}

	/**
	 * Return the last-modified timestamp of the file that corresponds
	 * to the target resource URL (i.e. typically the request ".jsp" file).
	 * Will simply return -1 if "applyLastModified" is false (the default).
	 * <p>Returns no last-modified date before the startup time of this servlet,
	 * to allow for message resolution etc that influences JSP contents,
	 * assuming that those background resources might have changed on restart.
	 * <p>Returns the startup time of this servlet if the file that corresponds
	 * to the target resource URL coudln't be resolved (for example, because
	 * the WAR is not expanded).
	 * @see #determineResourceUrl
	 * @see #getFileTimestamp
	 */
	protected final long getLastModified(HttpServletRequest request) {
		if (this.applyLastModified) {
			String resourceUrl = determineResourceUrl(request);
			if (resourceUrl == null) {
				resourceUrl = this.defaultUrl;
			}
			if (resourceUrl != null) {
				String[] resourceUrls = StringUtils.tokenizeToStringArray(resourceUrl, RESOURCE_URL_DELIMITERS);
				long latestTimestamp = -1;
				for (int i = 0; i < resourceUrls.length; i++) {
					long timestamp = getFileTimestamp(resourceUrls[i]);
					if (timestamp > latestTimestamp) {
						latestTimestamp = timestamp;
					}
				}
				return (latestTimestamp > this.startupTime ? latestTimestamp : this.startupTime);
			}
		}
		return -1;
	}

	/**
	 * Return the file timestamp for the given resource.
	 * @param resourceUrl the URL of the resource
	 * @return the file timestamp in milliseconds, or -1 if not determinable
	 */
	protected long getFileTimestamp(String resourceUrl) {
		ServletContextResource resource = new ServletContextResource(getServletContext(), resourceUrl);
		try {
			long lastModifiedTime = resource.lastModified();
			if (logger.isDebugEnabled()) {
				logger.debug("Last-modified timestamp of " + resource + " is " + lastModifiedTime);
			}
			return lastModifiedTime;
		}
		catch (IOException ex) {
			logger.warn("Couldn't retrieve last-modified timestamp of [" + resource +
					"] - using ResourceServlet startup time");
			return -1;
		}
	}

}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
51久久夜色精品国产麻豆| 91精品蜜臀在线一区尤物| 精品精品欲导航| 免费av网站大全久久| 欧美日韩一区久久| 亚洲国产一区二区三区青草影视| 99国产欧美另类久久久精品| 欧美性大战xxxxx久久久| 亚洲一级不卡视频| 91精品国产色综合久久ai换脸 | 欧美精选在线播放| 亚洲高清免费视频| 欧美本精品男人aⅴ天堂| 国产精品二区一区二区aⅴ污介绍| 国产成人精品亚洲777人妖| 欧美韩国日本一区| 色婷婷综合五月| 日韩国产欧美视频| 久久女同性恋中文字幕| 97久久精品人人澡人人爽| 亚洲综合一区二区三区| 3atv一区二区三区| 国产一区三区三区| 亚洲精品视频免费看| 欧美精品一二三区| 狠狠色丁香婷综合久久| 欧美日本免费一区二区三区| 老司机精品视频一区二区三区| 国产欧美日韩视频一区二区| 欧美综合一区二区三区| 久久99久久精品| 中文字幕一区二区三区四区| 欧美麻豆精品久久久久久| 国产河南妇女毛片精品久久久| 亚洲乱码国产乱码精品精98午夜 | 91在线视频免费91| 日本不卡一二三| 国产精品久久久久影院亚瑟| 欧美亚洲自拍偷拍| 国产盗摄视频一区二区三区| 亚洲国产成人tv| 国产精品五月天| 日韩一级精品视频在线观看| 成人爽a毛片一区二区免费| 亚洲第一福利视频在线| 国产日韩视频一区二区三区| 欧美日韩成人一区二区| 成人毛片在线观看| 久久国产尿小便嘘嘘| 亚洲精品久久久蜜桃| 国产午夜精品理论片a级大结局| 91黄色小视频| 国产在线一区观看| 三级欧美在线一区| 亚洲人成在线观看一区二区| 337p粉嫩大胆色噜噜噜噜亚洲 | 成人精品视频网站| 秋霞电影一区二区| 亚洲男帅同性gay1069| 26uuu精品一区二区| 欧美三级资源在线| 日本精品视频一区二区三区| 国产成人欧美日韩在线电影| 美女精品自拍一二三四| 夜色激情一区二区| 亚洲乱码精品一二三四区日韩在线| 亚洲国产精品v| 日韩免费高清电影| 欧美一区二区三区四区高清| 欧美亚洲一区三区| 色欧美日韩亚洲| 国产91精品久久久久久久网曝门| 久久不见久久见免费视频1| 日韩精品乱码av一区二区| 9191成人精品久久| 精品视频1区2区| 欧美性高清videossexo| 色拍拍在线精品视频8848| 亚洲午夜三级在线| 亚洲午夜一二三区视频| 亚洲精品一卡二卡| 亚洲乱码一区二区三区在线观看| 亚洲精品视频在线观看网站| 中文字幕一区二区三区精华液| 国产精品久久久久久久久搜平片 | 欧美日韩一卡二卡| 欧美自拍偷拍午夜视频| 欧美熟乱第一页| 欧美手机在线视频| 4438成人网| 欧美电影精品一区二区| 日韩精品中文字幕在线一区| 26uuu另类欧美亚洲曰本| 久久精子c满五个校花| 国产亚洲欧美中文| 综合婷婷亚洲小说| 伊人一区二区三区| 日韩中文字幕区一区有砖一区| 日本不卡在线视频| 国产在线国偷精品免费看| 国产不卡在线一区| 日本高清不卡一区| 欧美精品一卡两卡| 欧美男男青年gay1069videost | 色88888久久久久久影院野外| 欧美日韩小视频| 欧美变态凌虐bdsm| 中文天堂在线一区| 亚洲福利一区二区三区| 天天影视网天天综合色在线播放| 蜜臀av在线播放一区二区三区 | 91丨porny丨国产| 欧美午夜免费电影| 日韩一二三四区| 国产亚洲精品久| 亚洲一级在线观看| 国产一区二三区| 91亚洲精品久久久蜜桃| 欧美一区二区在线看| 中文字幕中文字幕一区| 亚洲123区在线观看| 国产成人在线网站| 91久久线看在观草草青青| 欧美成人精品1314www| 国产精品伦理一区二区| 日韩中文字幕不卡| av午夜一区麻豆| 日韩精品中午字幕| 亚洲影院理伦片| 国产美女久久久久| 欧美日韩aaa| 国产欧美精品区一区二区三区| 亚洲va韩国va欧美va| 国产乱子轮精品视频| 欧美日韩一级视频| 国产欧美日本一区视频| 日韩国产欧美三级| 91福利社在线观看| 久久网这里都是精品| 午夜在线电影亚洲一区| 成人三级在线视频| 日韩精品一区二区三区四区视频 | 亚洲激情在线激情| 国产乱人伦精品一区二区在线观看 | 欧美亚洲综合另类| 国产精品成人免费精品自在线观看| 寂寞少妇一区二区三区| 精品视频一区三区九区| 国产精品麻豆网站| 激情六月婷婷久久| 欧美日韩精品欧美日韩精品一 | 国内欧美视频一区二区| 91久久线看在观草草青青| 99久久国产综合色|国产精品| 日韩一二三区视频| 日韩在线一区二区三区| 欧美日本在线看| 亚洲国产日韩a在线播放性色| 91丨porny丨蝌蚪视频| 中文字幕欧美一区| 亚洲国产综合色| 99精品黄色片免费大全| 国产精品国产自产拍高清av| 国产91在线|亚洲| 久久亚洲私人国产精品va媚药| 日韩中文欧美在线| 欧美精品一级二级三级| 午夜视频在线观看一区| 欧美日韩中文字幕一区二区| 夜夜嗨av一区二区三区网页| 99精品国产视频| 综合亚洲深深色噜噜狠狠网站| a美女胸又www黄视频久久| 国产精品久久久一本精品| av在线不卡免费看| 中文字幕视频一区| 在线精品视频一区二区三四| 一区二区国产视频| 欧美日韩国产一区| 日韩高清不卡在线| 精品国产制服丝袜高跟| 国产剧情av麻豆香蕉精品| 久久九九久久九九| 91亚洲精品一区二区乱码| 亚洲国产成人porn| 国产美女精品一区二区三区| 666欧美在线视频| 久久99精品一区二区三区| 久久麻豆一区二区| 97aⅴ精品视频一二三区| 亚洲一区中文日韩| 欧美男同性恋视频网站| 美女视频免费一区| 国产女同性恋一区二区| eeuss鲁一区二区三区| 香蕉成人伊视频在线观看| 久久色在线视频| 色综合天天天天做夜夜夜夜做| 亚洲成人av电影| 久久人人超碰精品|