鏈緥涓敤鍒頒簡,commons-fileupload.jar
聽
聽
index.jsp
聽
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
聽 <head>
聽聽聽 <base href="<%=basePath%>" target="_blank" rel="external nofollow" >聽聽聽
聽聽聽 <title>鏂囦歡涓婁紶</title>
聽<link rel="stylesheet" type="text/css" href="UploadDialog/css/Ext.ux.UploadDialog.css" target="_blank" rel="external nofollow" />
聽聽聽 <link rel="stylesheet" type="text/css" href="scripts/ext/resources/css/ext-all.css" target="_blank" rel="external nofollow" />
聽<script type="text/javascript" src="scripts/ext/adapter/ext/ext-base.js"></script>
聽<script type="text/javascript" src="scripts/ext/ext-all.js"></script>
聽<script type="text/javascript" src="user/upload.js"></script>
聽<script type="text/javascript" src="UploadDialog/Ext.ux.UploadDialog.js"></script>
聽<script type="text/javascript" src="UploadDialog/Ext.ux.UploadDialog.packed.js"></script>
聽 聽<script type="text/javascript" src="UploadDialog/locale/zh_CN.js"></script>
聽 </head>
聽
聽
聽 <body>
聽 <div id="my-dlg"></div>
聽 </body>
</html>
聽
upload.js
聽
Ext.onReady(function() {聽聽聽
var dialog = new Ext.ux.UploadDialog.Dialog(聽聽聽
{ url: 'upload',
聽 reset_on_hide: false,
聽 allow_close_on_upload: true,
聽 upload_autostart: false
});聽聽聽
dialog.show('my-dlg');
});聽
聽
Upload .java
聽
package com.vol.upload;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
public class Upload extends HttpServlet {
聽
聽private static final long serialVersionUID = 7440302204266787092L;
聽public void doPost(HttpServletRequest request, HttpServletResponse response)
聽聽聽throws IOException, ServletException {
聽聽String savePath = "d:/";//淇濆瓨璺緞
聽聽String uploadPath = "d:/"; //涓婁紶璺緞
聽聽try {
聽聽聽System.out.println("寮€濮嬭繘琛屾枃浠朵笂浼?);
聽聽聽DiskFileUpload fu = new DiskFileUpload();
聽聽聽fu.setSizeMax(4194304); // 锟斤拷锟斤拷锟斤拷锟斤拷募锟斤拷叽鏈€澶э拷锟斤拷锟斤拷锟?MB聽聽
聽聽聽fu.setSizeThreshold(4096); // 锟斤拷锟矯夥拷锟斤拷锟斤拷锟叫★拷锟界紦瀛?kb聽聽
聽聽聽fu.setRepositoryPath(uploadPath); // 锟斤拷锟斤拷锟斤拷時目錄聽聽
聽聽聽List fileItems = fu.parseRequest(request);
聽聽聽Iterator i = fileItems.iterator();
聽聽聽while (i.hasNext()) {
聽聽聽聽FileItem fi = (FileItem) i.next();
聽聽聽聽String fileName = fi.getName();// 锟斤拷锟斤拷募锟斤拷锟斤拷锟斤拷锟僥鹼拷锟斤拷锟?聽聽聽聽if (fileName != null) {
聽聽聽聽聽fi.write(new File(savePath + fileName));
聽聽聽聽}
聽聽聽}
聽聽聽response.setContentType("text/html;charset=GBK");
聽聽聽System.out.println("涓婁紶鎴愬姛");
聽聽聽response.getWriter().print(
聽聽聽聽聽"{'success':true,'message':'涓婁紶鎴愬姛'}");
聽聽} catch (Exception e) {
聽聽聽System.out.println("涓婁紶澶辮觸");
聽聽聽response.getWriter().print(
聽聽聽聽聽"{'success':false,'message':'涓婁紶澶辮觸'}");
聽聽}
聽}
}
聽
鍦ㄦ垜鐨勮祫婧愰噷鏈夋簮浠g爜.杩樻湁涓猻truts+EXTJS UploadDialog鐨勫疄鐜版簮浠g爜
聽