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
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

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

  • java read file

    java read documents in two ways: java.io and java.lang.ClassLoader When using the java.io, when java.lang.ClassLoader use it? (Note: If prior to read xml file java read file clearly aware of these two methods have been like! Can take much less to understa

  • JDBC example of a long time do not have JDBC forgot

    A back-up here to stay. The first: The second:

  • In the servlet use Bean

    According to Sun's definition, JavaBean is a reusable software components. In fact JavaBean is a Java class, through the package into a property and methods of treatment of a function or a business object, referred to as bean. Because JavaBean is ...

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • First Hibernate Example

    Curd a simple example. Source does not contain the dependent libraries, or playing too much of the package. PO object Note: One must have the default constructor 2 non-final modified. Otherwise useless lazy loading. UserDAOImpl category code, and other co

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries