1.1. Use Jspsmartupload to implement file upload 1.1.1. Create a new Web project 1.1.2. Upload page index.jsp
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 " pageencoding=" Utf-8 "%><! DOCTYPE html>
|
1.1.3. File Upload processing Filesmartupload.java
Package com.jsp.file.upload.servlet; Import Java.io.ioexception;import java.sql.SQLException; Import Javax.servlet.servletexception;import Javax.servlet.annotation.webservlet;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.HttpServletResponse; Import Com.jspsmart.upload.smartupload;import com.jspsmart.upload.SmartUploadException; @WebServlet ("/filesmartupload") public class Filesmartupload extends HttpServlet {private static final long Seri Alversionuid = 1L; public void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexce Ption, ioexception{//Create File Upload object Smartupload smartupload = new Smartu Pload (); Initialize File Upload Object Smartupload.initialize (This.getservletconfig (), request, response); Sets the maximum number of bytes for a single file Smartupload.setmaxfilesize (1000*100); Sets the maximum number of bytes for the total file smartupload.settotalmaxfilesize (1000*1000*100); Set the allowable file extension smartupload.setallowedfileslist ("Jpg,doc,rar,txt,java"); try {//Set disallowed file extension smartupload.setdeniedfileslist ("exe,php"); Upload file Smartupload.upload (); Save the file, specify the path to Smartupload.save ("d://"); } catch (SQLException e) {e.printstacktrace (); } catch (Smartuploadexception e) {e.printstacktrace (); } } }
|
Using Jspsmartupload to implement file uploads