The path to growth-jspsmart + servlet allows you to upload images and generate thumbnails

Source: Internet
Author: User

          My JSP 'imageLoadTest.jsp' starting page                           

Servlet: mageLoadServlet. jsp

ImageLoadServlet = "jpg, gif, jpeg, png"; SmartUpload mySmartUpload = SmartUpload (); fileSizeMax = 1024*1024*10; String ext = ""; string url = "image/"; mySmartUpload. initialize (. getServletConfig (), request, response); mySmartUpload. setAllowedFilesList (allowedFilesList);} "only allow upload" + allowedFilesList + "Type Image" = mySmartUpload. getFiles (). getFile (0); (myFile. isMissing () {System. out. println ("select the file to upload" = myFile. getFileExt (); fileSize = myFile. getSize (); String saveurl = ""; (fileSize <= String. valueOf (Calendar. getInstance (). getTimeInMillis (); saveurl = request. getRealPath ("/"); saveurl + = url + filename + ". "+}" file saving error "java. io. file file = java. io. file (saveurl); String newSaveurl = request. getRealPath ("/") + url + filename + "_ min. "+ ext; Image image = javax. imageio. imageIO. read (file); tagSize = 200; oldWidth = image. getWidth (); oldHeight = image. getHeight (); width = 0 height = 0 tempdouble = 0 (oldWidth> = oldWidth/= oldHeight/= Math. round (oldWidth/= Math. round (oldHeight/= BufferedImage (width, height, BufferedImage. TYPE_INT_BGR); bufferedImage. getGraphics (). drawImage (image, 0, 0, width, height,); FileOutputStream newImage = FileOutputStream (newSaveurl); required imageencoder encoder = newImage. close (); response. sendRedirect ("index. jsp "" the file to be uploaded cannot exceed "+ (fileSizeMax/1024/1024) +" M"

Configuration File: web. xml

        ImageLoadServlet    com.servlet.ImageLoadServlet        ImageLoadServlet    /imageLoad            index.jsp  

 

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.