Save a period of jsp upload pictures code (a good red tape ... who has a good plug-in is not recommended ...)

Maintaining a very old project, added a photo upload feature electronics.
Using a SmartUpload. Good red tape ...
Tried JQuery plug-in Uploadify seemingly less suited to this project

<%@ page contentType="text/html;charset=GBK"%>
<%@page import="com.jspsmart.upload.SmartUpload"%>
<%@page import="java.util.Date"%>
<%@page import="com.jspsmart.upload.File"%>
<%@page import="java.awt.Image"%>

<base target="_self">
<link href="../../css/style.css" rel="stylesheet" type="text/css">

<BODY background="../../image/bg.jpg"  leftMargin=0 topMargin=0>
<div>
        <div>
                <form action="uploadpic.jsp?oper=upload" method="post" enctype="multipart/form-data" name="form2">
                <br>
                <input type="file" name="pic">
                <p> Please upload pictures of recent passport size documents  ! Photo size height 105 to  210 Pixels, width  75 To 150 pixels  , The file size within the 50KB  !</p>
        <p> If the photos do not meet the requirements, please download the  <a href="#"> The picture processing program  </a> For processing  .</p>
        <input type="submit" value=" Start upload  " >
        <input type="button"  value=" Close window  ">

        </form>
        </div>
</div>
<%
        String oper = request.getParameter("oper");
        if("upload".equals(oper)){

                SmartUpload mySmartUpload = new SmartUpload();
                mySmartUpload.initialize(pageContext);
                try {
                        mySmartUpload.upload();
                } catch (Exception e){
                %>
                  <SCRIPT language=javascript>
                  alert(" Only allow uploading .jpg and  .jpeg Type the picture file  ");
                  window.location='uploadpic.jsp';
                  </script>
        <%
                }File myFile = mySmartUpload.getFiles().getFile(0);
                        if (myFile.isMissing()){%>
                           <SCRIPT language=javascript>
                           alert(" Please select a file to upload  ");
                           </script><%}
                        else{
                            boolean flagOne = true;
                            if(myFile.getFileExt().equals("jpg")||myFile.getFileExt().equals("JPG")||myFile.getFileExt().equals("jpeg")){
                            }
                            else{
                                flagOne = false;
                                %>
                                <script language=javascript>
                                          alert(" Only allow uploading .jpg picture file type  ");
                                          </script>
                                          <%
                            }
                            if(myFile.getSize()>50000){
                                flagOne = false;
                                %>
                                <script language=javascript>
                                          alert(" Only allowed file size of the picture file in the 50KB  ");
                                          </script>
                                          <%
                            }
                            if(flagOne){
                                String myFileName = String.valueOf(new Date().getTime())+".jpg";
                                    myFile.saveAs("/upload/"+myFileName,myFile.SAVEAS_VIRTUAL);
                                    java.io.File file = new java.io.File(request.getRealPath("/")+"upload/"+myFileName);
                                    if(file.exists()){
                                        Image src = javax.imageio.ImageIO.read(file);
                                        boolean flag = true;
                                        int old_w=src.getWidth(null);
                                        int old_h=src.getHeight(null);
                                        if(old_w < 75 || old_w > 150){
                                                flag = false;
                                %>
                                        <script language=javascript>
                                                  alert(" Only allow uploads width of 75 to  150 Pixel picture file  ");
                                                  </script>
                                                  <%
                                        }
                                        if(old_h < 105 || old_h > 210){
                                                flag = false;
                                %>
                                        <script language=javascript>
                                                  alert(" Only allow uploads height 105 to  210 Pixel picture file  ");
                                                  </script>
                                                  <%
                                        }
                                        if(flag){
                                                %>
                                            <SCRIPT language=javascript>
                                            window.returnValue = '<%=myFileName%>';
                                            </script>
                                            <%
                                        }
                                }
                            }

                          }
        }
 %>
</body>

Main window of the body:

t = window.showModalDialog('uploadpic.jsp','DialogWidth:450px;DialogHeight:350px;help:no;status:no');

take callback value

分类:Java 时间:2009-01-02 人气:270
分享到:
blog comments powered by Disqus

相关文章

  • On upload multipart / form-data of the post does not receive the text parameter problem 2010-05-27

    On upload multipart / form-data of the post does not receive the text parameter problem When we use the multipart / form-data upload time. Input box will transfer the contents of binary files. So we were in the process request can not be achieved wit

  • On the use of multipart / form-data file upload to do a little thinking 2010-06-07

    In recent days, when doing file upload using enctype = "multipart / form-data" when, in the spring of the controller which is not like that kind of Formfile struts like a good package, class, can get inside such a form value. Perhaps you will sa

  • Implementation file upload JSP 2010-12-15

    <form action="AddFilePath" method="post" enctype="multipart/form-data" > <input type="file" name="X" /> <input type="submit" value=" Upload "/> </form> package t

  • Jsp upload files using components 2010-10-20

    1> First create a HTML page. Note that all files to upload the form enctype attribute must be set, and the value of the property must be a multipart / form-data, while the request method must be POST. <form name="myform" action="fileu

  • [Transfer] SWFUpload + COS + servelet upload component upload large attachments to achieve 2010-11-30

    First, the needs and background: the company had net monthly meeting of the document much more than 50M, the original upload component using struts upload + io flows through the General Assembly if the uploaded file causes a memory overflow. And ther

  • [Java] servlet implement file upload with upload progress bar 2010-11-04

    This problem, I tried a few days, the file is uploaded, but have been unable to show progress, then I side of the access to information, while modified, was finally resolved, I hope you help me to top up, oh. Requires two JAR archive file Download: T

  • swfUpload java file upload component upload.war 2010-10-28

    swfUpload java file upload component upload.war placed directly under the webapps directory. Upload file exists webapps \ upload \ files directory upload_src.rar Eclipse project source code Support for multiple file upload.

  • jsp upload images to Oracle database 2010-12-21

    Ah turn jsp upload pictures to the Oracle database, the first step: to establish a database create table test_img (id number (4), name varchar (20), pic long raw); Step two: (NewImg.html) <html> <head> <title> add pictures </ title>

  • jsp upload component used in js 2010-08-02

    1 First of all, the introduction of plug-ins page to jquery.uploadify Write the following code in the page <div> <div> <br/> Add Attachment: <input type="file" name="uploadify" value="aaaaaaaa"/> <d

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.683 (s). 12 q(s)