`

upload code

阅读更多
package org.uploadtag.servlet;

import java.io.IOException;
import java.util.List;

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

import org.apache.commons.fileupload.FileUploadBase;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.uploadtag.commonsfileupload.MonitoredDiskFileItem;
import org.uploadtag.commonsfileupload.MonitoredDiskFileItemFactory;
import org.uploadtag.commonsfileupload.UploadListener;
import org.uploadtag.service.impl.UploadServiceImpl;
import org.uploadtag.sessionobjects.UploadError;



public class UploadServlet extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("UploadServlet:doGet");

	}


	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("UploadServlet:doPost");
		String areaID = request.getParameter("areaID");
	    String attachmentID = request.getParameter("attachmentID");
	    System.out.println("UploadServlet:doPost: attachmentID = " + attachmentID);
	    String maxSizeString = request.getParameter("maxSize");
	    int maxSize = 0;
	    if ((maxSizeString!=null)&&(!maxSizeString.equals(""))) {
	    	maxSize = Integer.parseInt(maxSizeString);
	    }
	    System.out.println("UploadServlet:doPost: maxSizeString = " + maxSizeString);
	    System.out.println("UploadServlet:doPost: maxSize = " + maxSize);

        UploadServiceImpl service = new UploadServiceImpl(request.getSession());
	    UploadListener listener = new UploadListener(request, service, areaID, attachmentID,30);

	    service.cleanUploadErrorStatus(areaID,attachmentID);

	    // Create a factory for disk-based file items
	    MonitoredDiskFileItemFactory factory = new MonitoredDiskFileItemFactory(listener);
	    // Create a new file upload handler
	    ServletFileUpload upload = new ServletFileUpload(factory);
	    if (maxSize>0) {
	    	upload.setSizeMax(maxSize*1024);
	    }

	    try
	    {
	        // process uploads ..
	        upload.parseRequest(request);
	    }
	    catch (FileUploadBase.SizeLimitExceededException e) {
	    	e.printStackTrace();
			//new ExceptionUtil().logMessageForException(e);
			//new ExceptionUtil().sendMessageForException(e);
			service.updateUploadErrorStatus(areaID,attachmentID,UploadError.FILE_SIZE_LIMIT);
	    }
	    catch (FileUploadException e)
	    {
	    	e.printStackTrace();
			//new ExceptionUtil().logMessageForException(e);
			//new ExceptionUtil().sendMessageForException(e);
	    }

	    List fileItemList = factory.getFileItems();
	    service.saveFileItemsListInSession(areaID, attachmentID,fileItemList);
	    System.out.println("UploadServlet:doPost: itemList = " + fileItemList);
	    System.out.println("UploadServlet:doPost: itemList.size() = " + fileItemList.size());
	    for (int i=0;i<fileItemList.size();i++) {
	    	MonitoredDiskFileItem item = (MonitoredDiskFileItem)fileItemList.get(i);
	    	System.out.println("UploadServlet:doPost: item = " + item);
	    	System.out.println("UploadServlet:doPost: item.getName() = " + item.getName());
	    }



	}




}

 

分享到:
评论

相关推荐

    youtube upload sample source code

    youtube upload sample source code

    Android代码-Garage doors opener

    To reproduce my system you need to know how to upload code to the ESP8266 and to the Arduino Uno. If you are able to code, you don't have to use an Arduino Uno, you only need to use an ESP826

    VC 使用Http上传文件到web服务器同时使用http下载文件

    首先,`UploadCode.cpp`文件可能包含了HTTP文件上传的核心逻辑。HTTP文件上传通常涉及以下步骤: 1. 创建HTTP请求:首先,你需要构建一个HTTP POST请求,指定目标URL(即服务器的上传接口)和Content-Type头,通常...

    googlecode_upload

    往googlecode自动传文件 肯定成功 得先安装Python

    tym.zip_RAW_ekg_ekg data_raw data

    描述 "ekg raw data upload code" 表明这个压缩包可能包含了用于上传和处理心电图原始数据的程序。 标签 "raw ekg" 强调了数据的原始状态,即未经任何预处理或分析。"ekg_data" 和 "raw_data" 指出压缩包中的核心...

    web代码例子上传

    function uploadCode(file) { const formData = new FormData(); formData.append('codeFile', file); fetch('/uploadEndpoint', { method: 'POST', body: formData }).then(response =&gt; { if (response.ok)...

    Arduino Projects For Dummies

    It used to be pretty difficult for the average person to program and upload code to microcontrollers - and they were a lot more expensive! So even if you got the code working, if you then hooked it ...

    Chilkat.Upload activex 上传组件

    $success = $chilkat-&gt;unlockComponent("your unlock code"); if ($success != 1) { echo "Error unlocking component."; exit; } $filePaths = array("path/to/file1", "path/to/file2"); $success = $...

    [上传下载]免费图片上传站程序_upload_code.zip

    【标题】:“[上传下载]免费图片上传站程序_upload_code.zip”揭示了一个关于构建免费图片上传站点的程序代码。这个压缩包可能包含了实现这样一个服务所需的所有核心组件,包括服务器端的处理逻辑、用户界面(UI)的...

    netsuite-upload:VS Code扩展,用于上传和下载NetSuite SuiteScript文件和文件夹

    netsuite-up VS Code插件 netsuite-upload是一个Visual Studio Code扩展,允许您直接从VS Code管理SuiteScript文件。 它还可以帮助您定义新模块和添加服务器端模块相关性。特征1.在VS Code和NetSuite文件柜之间推...

    uploadpicture

    response.isSuccessful()) throw new IOException("Unexpected code " + response); // 假设服务器返回了上传成功的状态码,如 200 String responseBody = response.body().string(); Log.d("UploadPicture", ...

    IDEA代码检视插件Code Review Helper(支持团队协同)

    4. 选择“Upload Plugin”(上传插件)选项,导入解压后的插件源代码。 5. 完成安装后,重启IDEA,即可在工具栏找到并使用Code Review Helper插件。 总的来说,Code Review Helper插件是IntelliJ IDEA用户进行高效...

    Android代码-upload-pgyer-plugin

    Pgyer can upload the application to the site, generate installation link and qr code user to open the installation link, or scan code qr code, can start installation. So this plugin can be uploaded to...

    upload

    例如,开发过程中可能使用Postman进行API测试,使用Visual Studio Code或Sublime Text等编辑器编写代码,使用Git进行版本控制,使用Docker进行环境隔离等。 在文件“Upload”中,可能包含了实现上传功能的相关代码...

    el-upload多文件一次性上传(携带json),自定义上传事件(手动上传),不使用action属性上传.pdf

    if (res.code === '200') { this.$message.success('上传成功') } }).catch(() =&gt; {}) } else { return false } }) } ``` ### 情况二:复杂表单上传 对于更复杂的表单,可能有多个文件选择器,我们不再...

    jquery 插件ajaxupload 的简单应用

    &lt;script src="https://code.jquery.com/jquery-3.x.min.js"&gt;&lt;/script&gt; &lt;script src="ajaxupload.js"&gt; ``` 2. **创建上传元素** 创建一个HTML元素,通常是一个`&lt;input type="file"&gt;`标签,用于触发文件选择...

    CODE_UPLOAD100939232000_meme_midi_

    标题中的"CODE_UPLOAD100939232000_meme_midi_"似乎是一种编码或标识符,可能代表上传的特定版本或者时间戳,而"meme_midi"部分则暗示了这个压缩包内容与MIDI(Musical Instrument Digital Interface)格式的音乐...

    code upload

    上传源码文件为配合SeedVPM642板视频开发,从合众达公司购买的最新的源码库 除源码外,均配有使用说明,我已经搜索过,贵站应该没有相同的代码 在源码最后,上载了H.264标准白皮书 编译环境为CCS ...

    Delphi.example.code.TIdFTP.File.Upload.rar_*TidFTP*_delphi examp

    Delphi基于TIdFTP文件上传实例代码Delphi example code based on TIdFTP File Upload

    jQuery File Upload

    •Style Guide with explanations for the provided CSS code. •Using the plugin with jQuery UI. •How to submit additional Form Data. •How to submit files asynchronously. •Upload multiple resolutions ...

Global site tag (gtag.js) - Google Analytics