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

相关文章

  • 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

  • [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>

  • 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 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

  • [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

  • 第四十五讲:tapestry upload组件使用input type="file"实现上 2012-04-28

    此教程我们使用常用的multipart/form-data同过post方式实现上传,上传实现依旧使用了 tapestry的UploadedFile组件,我随便写了个字符串to,这个字符串可以随便命名的,没有具体实际意义,作用就是传一个值到上传处理页面让它知道执行了上传这个动作.还需要创建一个解码器.代码如下: UploadTypeFile.tml <html t:type="layout" title="tapestryStart Index" t:sideb

  • Air link href = "#" problem. Base open iframe tag and two-goal window.parent.location 2009-09-21

    http://hi.baidu.com/zdz8207/blog/item/e5a5379b38610fb1c9eaf494.html When the use of javascript, usually through something like this: <a href="#""javascript: Method "> submit </ a> Manner, through a pseudo-link to call the j

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

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

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

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