⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multipartfilter.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
字号:
/* * Copyright 2005 The Apache Software Foundation. *  * 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.apache.myfaces.component.html.util;import java.io.IOException;import javax.servlet.Filter;import javax.servlet.FilterChain;import javax.servlet.FilterConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.commons.fileupload.FileUpload;/** * This filters is mandatory for the use of many components. * It handles the Multipart requests (for file upload) * It's used by the components that need javascript libraries * * @author Sylvain Vieujot (latest modification by $Author: oros $) * @author <a href="mailto:oliver@rossmueller.com">Oliver Rossmueller </a> * @version $Revision: 1.1 $ $Date: 2005/03/20 23:16:08 $ */public class MultipartFilter implements Filter{    private int uploadMaxFileSize = 100 * 1024 * 1024; // 10 MB    private int uploadThresholdSize = 1 * 1024 * 1024; // 1 MB    private String uploadRepositoryPath = null; //standard temp directory    public void init(FilterConfig filterConfig)    {        uploadMaxFileSize = resolveSize(filterConfig.getInitParameter("uploadMaxFileSize"), uploadMaxFileSize);        uploadThresholdSize = resolveSize(filterConfig.getInitParameter("uploadThresholdSize"), uploadThresholdSize);        uploadRepositoryPath = filterConfig.getInitParameter("uploadRepositoryPath");    }    private int resolveSize(String param, int defaultValue)    {        int numberParam = defaultValue;        if (param != null)        {            param = param.toLowerCase();            int factor = 1;            String number = param;            if (param.endsWith("g"))            {                factor = 1024 * 1024 * 1024;                number = param.substring(0, param.length() - 1);            } else if (param.endsWith("m"))            {                factor = 1024 * 1024;                number = param.substring(0, param.length() - 1);            } else if (param.endsWith("k"))            {                factor = 1024;                number = param.substring(0, param.length() - 1);            }            numberParam = Integer.parseInt(number) * factor;        }        return numberParam;    }    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException    {        if (!(response instanceof HttpServletResponse))        {            chain.doFilter(request, response);            return;        }        HttpServletRequest httpRequest = (HttpServletRequest) request;        // For multipart/form-data requests        if (FileUpload.isMultipartContent(httpRequest))        {            chain.doFilter(new MultipartRequestWrapper(httpRequest, uploadMaxFileSize, uploadThresholdSize, uploadRepositoryPath), response);        } else        {            chain.doFilter(request, response);        }    }    public void destroy()    {        // NoOp    }}

⌨️ 快捷键说明

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