锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
聽 <form method="post" action="uploadimage.jsp" name="form1" enctype="multipart/form-data">
聽 <input type="file" name="file">
聽 <input type="submit" name="sub" value="upload">
聽聽 </form>
uploadimg.jsp 鏂囦歡浠g爜濡備笅錛?br /><%@ page language="java"聽 pageEncoding="gb2312"%>
<%@ page import="java.io.*,java.awt.Image,java.awt.image.*,com.sun.image.codec.jpeg.*,java.sql.*,com.jspsmart.upload.*,java.util.*"%>
<%@ page import="mainClass.*" %>
<html>
聽 <head>
聽聽聽 <title>My JSP 'uploadimage.jsp' starting page</title>
聽 </head>
聽
聽 <body>
聽聽聽 <%
聽聽聽 SmartUpload sma=new SmartUpload();
聽聽聽
聽聽聽 long file_max_size=4000000;
聽聽聽
聽聽聽 String filename1="",ext="",testvar="";
聽聽聽
聽聽聽 String url="uploadfiles/";
聽聽聽
聽聽聽 sma.initialize(pageContext);
聽聽聽
聽聽聽 try
聽聽聽 {
聽聽聽 sma.setAllowedFilesList("jpg,gif");
聽聽聽
聽聽聽 sma.upload();
聽聽聽
聽聽聽 }catch(Exception e){
聽聽聽 %>
聽聽聽 <script language="jscript">
聽聽聽 alert("鍙厑璁鎬笂浼爅pg,gif鍥劇墖")
聽聽聽 window.location.href="upfile.jsp"
聽聽聽 </script>
聽聽聽 <%
聽聽聽 }
聽聽聽 try{
聽聽聽 com.jspsmart.upload.File myf=sma.getFiles().getFile(0);
聽聽聽
聽聽聽 if(myf.isMissing()){
聽聽聽
聽聽聽 %>
聽聽聽 <script language="jscript">
聽聽聽 alert("璇烽夋嫨瑕佷笂浼犵殑鏂囦歡!")
聽聽聽 window.location.href="upfile.jsp"
聽聽聽 </script>
聽聽聽 <%
聽聽聽 }else{
聽聽聽
聽聽聽 ext=myf.getFileExt();
聽聽聽
聽聽聽 int file_size=myf.getSize();
聽聽聽
聽聽聽 String saveurl="";
聽聽聽
聽聽聽 if(file_size < file_max_size){
聽聽聽
聽聽聽 Calendar cal=Calendar.getInstance();
聽聽聽
聽聽聽 String filename=String.valueOf(cal.getTimeInMillis());
聽聽聽
聽聽聽 saveurl=request.getRealPath("/")+url;
聽聽聽
聽聽聽 saveurl+=filename+"."+ext;
聽聽聽
聽聽聽 myf.saveAs(saveurl,sma.SAVE_PHYSICAL);
聽聽聽
聽聽聽 myclass mc=new myclass(request.getRealPath("data/data.mdb"));
聽聽聽
聽聽聽 mc.executeInsert("insert into [path] values('uploadfiles/"+filename+"."+ext+"')");
聽聽聽
聽聽聽 out.println("鍥劇墖涓婁紶鎴愬姛!");
聽聽聽
聽聽聽 response.sendRedirect("showimg.jsp");
聽聽聽 }
聽聽聽
聽聽聽 }
聽聽聽
聽聽聽 }catch(Exception e){
聽聽聽 e.printStackTrace();
聽聽聽 }
聽聽聽 %>
聽 </body>
</html>