資源描述:
《JSP中上傳圖片完整代碼.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫(kù)。
1、upfile.jsp
2、uploadimage.jspuploadimage.jsp<%@pagelanguage="java"pageEncoding="gb2312"%><%@pageimport="java.io.*,java.awt.image.*,com.sun.image.codec.jpeg.*,java.sql.*,com.jspsmar
3、t.upload.*,java.util.*"%><%@pageimport="mainClass.*"%>
MyJSP'uploadimage.jsp'startingpage<%SmartUploadsma=newSmartUpload();longfile_max_size=4000000;Stringfilename1="",ext="",testvar="";Stringurl="uploadfiles/";sma.initialize(pageContext);try{sma.s
4、etAllowedFilesList("jpg,gif");sma.upload();}catch(Exceptione){%>alert("只允許上傳jpg,gif格式圖片");window.location.href="upfile.jsp"<%}try{com.jspsmart.upload.Filemyf=sma.getFiles().getFile(0);if(myf.isMissing()){%>alert("請(qǐng)選擇要上傳的文件!");
5、window.location.href="upfile.jsp"<%}else{ext=myf.getFileExt();intfile_size=myf.getSize();Stringsaveurl="";if(file_size6、"+ext;myf.saveAs(saveurl,sma.SAVE_PHYSICAL);myclassmc=newmyclass(request.getRealPath("data/data.mdb"));mc.executeInsert("insertinto[path]values('uploadfiles/"+filename+"."+ext+"')");//檢查out.println("圖片上傳成功!");response.sendRedirect("showimg.jsp");}}}catch(Exceptione){e.printStackTrace();
7、}%>