SimpleUpload.jsp
上传用户:nbluoke
上传日期:2013-08-09
资源大小:4851k
文件大小:3k
源码类别:

教育系统应用

开发平台:

WORD

  1. <%@ page contentType="text/html; charset=gb2312" language="java"  errorPage="" %>
  2. <%@ page  import="javazoom.upload.*,java.util.*" %>
  3. <%@ page import="java.text.*" %>
  4. <%@ page import="java.util.*" %>
  5. <%@ page import="jinghua.JinghuaConn" %>
  6. <jsp:useBean id="upBean" scope="page" class="javazoom.upload.UploadBean" >
  7.   <jsp:setProperty name="upBean" property="folderstore" value="/sfroot/home/groups/jsptestonline/editor/pic" />
  8. </jsp:useBean>
  9. <html>
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  12. </head>
  13. <body leftmargin="2" topmargin="0" marginwidth="0" marginheight="0">
  14. <%    Date nowtime=new java.util.Date();
  15.       SimpleDateFormat sf=new SimpleDateFormat("yyyyMMddHHmmssSSS");
  16.       String time1=sf.format(nowtime);
  17.       String fname="";
  18.       String pathname="";
  19.      // mySmartUpload.initialize(pageContext);
  20.      // mySmartUpload.setTotalMaxFileSize(500000);
  21.       //mySmartUpload.upload();
  22.       String msg=null;
  23.       String strJS=null;
  24.       boolean show=false;
  25.       strJS="<SCRIPT language=javascript>" +"n";
  26.         //com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
  27.         //fname="pic/"+time1+"."+myFile.getFileExt();
  28.         //myFile.saveAs(fname, mySmartUpload.SAVE_VIRTUAL);
  29.     if (MultipartFormDataRequest.isMultipartFormData(request))
  30.       {
  31.          MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
  32.          String todo = mrequest.getParameter("todo");
  33.  if ( (todo != null) && (todo.equalsIgnoreCase("upload")) )
  34.  {
  35.                 Hashtable files = mrequest.getFiles();
  36.                 if ( (files != null) || (!files.isEmpty()) )
  37.                 {
  38.                     UploadFile file = (UploadFile) files.get("FileName");
  39.                     fname=file.getFileName();
  40.                     String exn=fname.substring(fname.length()-3);
  41.                     file.setFileName(time1+"."+exn);
  42.                     upBean.store(mrequest);
  43.                     file.reset();
  44.                      //生成JS脚本
  45.                     pathname="pic/"+time1+"."+exn;
  46.                    // strJS=strJS+"function tempfun(){n";
  47.                     strJS=strJS+"    var strhtml="<img src='"+pathname+"' border=0>";n";
  48.                     strJS=strJS+"    var win=parent.Composition.document;" +"n";
  49.                     strJS=strJS + "    parent.Composition.focus();" +"n";
  50.                     strJS=strJS+"    win.selection.createRange().pasteHTML(strhtml)"+"n";
  51.                     strJS=strJS+"    history.go(-1);" +"n";
  52.     strJS=strJS+ "    parent.Composition.focus();n";
  53.                    // strJS=strJS+"}";
  54.                     msg="文件上传成功!";
  55.                     show=true;
  56.                   }
  57.                 else
  58.         {
  59.                   msg="文件上传失败"+"No uploaded files";
  60.         }
  61.  }else
  62.          {
  63.            msg="文件上传失败"+"todo="+todo;
  64.          }
  65.       }
  66.       strJS=strJS + "alert('" + msg + "');" +"n";
  67.       strJS=strJS + "parent.Composition.focus();" +"n";
  68.       strJS=strJS + "</script>";
  69.       out.print(strJS);
  70.       //response.sendRedirect("upload.jsp");
  71. %>
  72. </body>
  73. </html>