Springmvc batch upload picture, realize upload picture preview before uploading _spring

Source: Internet
Author: User
Tags save file

Recently there is a function to upload pictures, and then realize the picture preview, because the project is older, at the same time the interface and user experience also requires not too high, did not go to find the online open source Plug-ins, directly wrote a simple function, here to do a record backup

Because this is an experimental small code, there is no too much validation and interface adjustment

can be implemented in random order deletion

This is the simple function interface, the following is the code

The first is that SPRINGMVC XM needs to be configured under

    <!--configuration multipartresolver for file uploads using spring's commosmultipartresolver Description: p:defaultencoding= "UTF-8": Here the default file encoding is set to UTF-8 Must be consistent with the default encoding of the user's JSP; 
        p:maxuploadsize= "5000000": Specify file Upload size in bytes; p:uploadtempdir= "fileupload/temp": File Upload temp directory, When the upload is complete, the temporary files will be deleted;-->
    <bean id= "multipartresolver"
        class= " Org.springframework.web.multipart.commons.CommonsMultipartResolver "
        p:defaultencoding=" UTF-8 "P: Maxuploadsize= "5000000" p:uploadtempdir= "fileupload/temp" >
    </bean>

Jsp+js

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%> <% String Path = Request.getcontextpath ()
;
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";  
Response.setheader ("Cache-control", "No-store");//http 1.1 Response.setheader ("Pragma", "No-cache");//http 1.0 Response.setdateheader ("Expires", 0);//prevents caching at the proxy server%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >  

Tool class

Package com.lovo.utils;

Import Java.util.Arrays;
Import java.util.List;

public class Fileuploadcheck {

    //Supported file types public
    static final list<string> allow_types = Arrays.aslist (" Image/jpg "," Image/jpeg "," Image/png "," image/gif ");

    Verify that the file type is a permitted public
    static Boolean allowupload (String postfix) {return
        allow_types.contains (postfix);
    }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.