惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
B
Blog RSS Feed
Y
Y Combinator Blog
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
aimingoo的专栏
aimingoo的专栏
Jina AI
Jina AI
The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
A
About on SuperTechFans
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Check Point Blog
M
MIT News - Artificial intelligence
Last Week in AI
Last Week in AI
V
V2EX
腾讯CDC
F
Fortinet All Blogs
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss

热爱生活与梦想

迁移LeanCloud的Waline评论数据到TiDB/Neon 25年江浙地区暑假自驾游之感慨 使用阿里云灵码继续完成构建 SSL 证书管理器 亲手给儿子做的棒棒糖摩天轮六一礼物 使用腾讯云 CodeBuddy 构建 SSL 证书管理器 修复代码块默认高度相关缺陷 HugoNexT4.7.2 新功能和升级提示 改善代码块折叠和选中功能 支持Github风格的警告样式 新增音乐短代码功能支持 给文章添加摘要和过期提示功能 回顾24年的过去总结 修复Mathjax行内显示公式的问题 给Hugo文章增加阅读更多跳转的锚点定位功能 Win10隐匿的VPN设置和L2TP连接常见错误 Go语言中“糟糕”的日期时间格式化设计 DaoCloud道客提供的免费Docker镜像代理服务 感谢万能淘宝让自己吃到喜欢的美食 WSL运行时遇到未知异常错误无法使用 隐藏的换行符导致Base64加密解密失败 MySQL自带客户端直接免密登录操作 Linux系统中删除目录软链接的注意项 Java程序调用外网API时CA问题 如何不关机重启WSL2恢复虚拟服务 在Windows上安装Podman容器平台做虚拟化 记一次无法弹出移动硬盘的记录 为友情链接添加自动检测脚本 重新激活Github的2FA认证 Linux中使用tar压缩命令排除文件 继续小米手环的健康生活之旅
JSP版本的KindEidtor在线编辑器第二季:Servlet+Struts2集成版
凡梦星尘 · 2011-10-18 · via 热爱生活与梦想

前段时间我在论坛上发布了一篇名为 《JSP版的完善KindEditor在线编辑器(带附件上传与图片按日期分类管理功能)》 得到了大家的积极响应,不过令我觉得有点遗憾的是,有很多人都不是真的讨论技术问题,而是向我索取源码,说实在的自已的劳动成果就这样白白奉献出来,觉得有点对不起自己了,要知道我们国内的技术员都是没有金钱后盾啊。唉,最近都太忙了就没有怎么太在意这件事,今晚刚好有空过来看看。看了那么多人留下的印记后,觉得自己也应该要无私一下才是吧,咱老毛说的对:要像雷锋同志学习,呵呵…… 其实在上面我已经说过了,这个JAR里面的功能我只是把官网的JSP代码改编而已,废话就先不多说了,下面直接上码吧,可要接稳了哦。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313

package com.elkan.kindeditor.upload;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import com.elkan.utils.ImageUtil;

/**
* 实现KindEditor图片上传的Servlet
* 
* @author SENHUI
* 
* @since 2011/03/21 20:20:23
*/
public class UploadImage extends HttpServlet {

   private static final long serialVersionUID = 5121794650920770832L;
   // 上传图片的最大宽度
   protected int MAX_WIDTH = -1;
   // 上传图片的最大高度
   protected int MAX_HEIGHT = -1;
   // 上传图片的大小
   protected long MAX_SIZE = 1000000;
   // 定义允许上传的图片的扩展名
   protected String[] IMAGETYPES = new String[] { "gif", "jpg", "jpeg", "png", "bmp" };
   // 定义上传图片保存目录路径
   protected String UPLOAD_PATH = "";	
   // 上传图片设置信息   
   protected String id = "";  
   // 上传图片的TITLE属性值
   protected String imgTitle = ""; 
   
   protected int imgWidth = -1;   
   
   protected int imgHeight = -1;   
   
   protected String imgBorder = "";   
   
   protected String resizeImg = "";
   
   protected boolean isFlag = false;
   
   protected String tempTitle = "";

   @SuppressWarnings("deprecation")
   @Override
   protected void doGet(HttpServletRequest request,
   		HttpServletResponse response) throws ServletException, IOException {
   	response.setContentType("text/html; charset=UTF-8");
   	PrintWriter out = response.getWriter();
   	String savePath = this.getInitParameter("UPLOAD_PATH");
   	if (savePath == null || savePath.isEmpty()) {
   		out.println(alertMsg("你还没设置上传图片保存的目录路径!"));
   		return;
   	}
   	//判断是否设置了上传图片的大小
   	if(this.getInitParameter("MAX_SIZE") != null){
   		MAX_SIZE = Integer.parseInt(this.getInitParameter("MAX_SIZE"));
   	}
   	//判断是否设置了上传图片的类型
   	if(this.getInitParameter("IMAGETYPES") != null){
   		IMAGETYPES = toArray(this.getInitParameter("IMAGETYPES"));
   	}
   	// 图片保存目录路径
   	String uploadPath = new StringBuffer(request.getSession().getServletContext().getRealPath("/")).append(savePath).toString();
   	
   	// 图片保存目录URL
   	String saveUrl = new StringBuffer(request.getContextPath()).append("/").append(savePath).toString();
   	
   	// 检查上传图片是否存在
   	if (!ServletFileUpload.isMultipartContent(request)) {
   		out.println(alertMsg("请选择你要上传的图片!"));
   		return;
   	}
   	
   	// 检查目录
   	File uploadDir = new File(uploadPath);
   	if (!uploadDir.isDirectory()) {
   		out.println(alertMsg("上传图片保存的目录不存在。"));
   		return;
   	}
   	
   	// 检查目录写权限
   	if (!uploadDir.canWrite()) {
   		out.println(alertMsg("上传图片保存的目录没有写权限。"));
   		return;
   	}
   	
   	// 准备上传图片
   	FileItemFactory factory = new DiskFileItemFactory();
   	ServletFileUpload upload = new ServletFileUpload(factory);
   	upload.setHeaderEncoding("UTF-8");
   	List<?> items = null;
   	String temp = null;
   	try {
   		items = upload.parseRequest(request);			
   		Iterator<?> itr = items.iterator();
   		while (itr.hasNext()) {
   			
   			FileItem item = (FileItem) itr.next();
   			 // 上传图片的原文件名   
   	        String fileName = item.getName(); 
   	        temp = (String) item.getName();
   	        if(temp != null && !isFlag){
   	        	temp = temp.substring(temp.lastIndexOf("\\")+1);
   	        	tempTitle = temp;
   	        	isFlag = true;
   	        }
   	         // KindEditor编辑器的ID  
   	        if(((String)item.getFieldName()).equals("id")){   
   	            id = item.getString(); 
   	        }  
   	       
   	        // 上传图片的重新提示
   	        if(((String)item.getFieldName()).equals("imgTitle")){   
   	            imgTitle = item.getString(); 
   	            if(imgTitle != null){
   	            	imgTitle = new String(imgTitle.getBytes("ISO8859-1"),"UTF-8");
   	            }
   	        } 
   	        // 设置图片的宽度
   	        if(((String)item.getFieldName()).equals("imgWidth")){   
   	           String imgWidth = item.getString();   
   	           if(imgWidth != null && !imgWidth.isEmpty()){
   	        	   this.imgWidth = Integer.parseInt(imgWidth);
   	           }
   	        }  
   	        // 设置图片的高度
   	        if(((String)item.getFieldName()).equals("imgHeight")){   
   	           String imgHeight = item.getString();   
   	           if(imgHeight != null && !imgHeight.isEmpty()){
   	        	   this.imgHeight = Integer.parseInt(imgHeight);
   	           }
   	        }
   	        // 设置图片的边框
   	        if(((String)item.getFieldName()).equals("imgBorder")){   
   	            imgBorder = item.getString();  
   	        } 
   	        
   			long fileSize = item.getSize();
   			if (!item.isFormField()) {						
   				// 检查文件大小
   				if (fileSize > MAX_SIZE) {
   					out.println(alertMsg("上传文件大小超过限制。"));
   					return;
   				}
   				
   				// 检查扩展名
   				String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
   				if (!Arrays.<String> asList(IMAGETYPES).contains(fileExt)) {
   					out.println(alertMsg("上传图片扩展名是不允许的扩展名。"));
   					return;
   				}
   				// 根据时间创建文件夹
   				SimpleDateFormat folderNameFormat = new SimpleDateFormat("yyyyMMdd");
   				String realPath = uploadPath + folderNameFormat.format(new Date());
   				File folder = new File(realPath);
   				boolean flag = folder.exists();
   				// 确认文件夹是否已经存在
   				if(!flag){
   					flag = folder.mkdir();
   				}
   				// 创建文件夹并上传图片
   				if(flag){
   					SimpleDateFormat fileNameFormat = new SimpleDateFormat("yyyyMMddHHmmss");					
   					String newFileName = fileNameFormat.format(new Date()) + "_"+ new Random().nextInt(1000) + "." + fileExt;						
   					File uploadedFile = new File(realPath, newFileName);						
   					item.write(uploadedFile);
   					resizeImg = uploadedFile.getPath();
   					resizeImg = resizeImg.replaceAll("\\\\", "/");
   					saveUrl += folderNameFormat.format(new Date()) + "/" + newFileName;						
   				}else{
   					System.out.println(" 文件夹创建失败,请确认磁盘没有写保护并且空件足够");
   				}	
   			}
   		}
   		
   		// 判断是否设置图片的最大宽度与高度
   		String max_width = this.getInitParameter("MAX_WIDTH");
   		String max_height = this.getInitParameter("MAX_HEIGHT");
   		if((max_width != null && !max_width.isEmpty())){
   			MAX_WIDTH = Integer.parseInt(max_width);
   		}
   		if(max_height != null && !max_height.isEmpty()){
   			MAX_HEIGHT = Integer.parseInt(max_height);
   		}
   		
   		if(imgTitle == null || imgTitle.isEmpty()){
   			imgTitle = tempTitle;
   		}
   		
   		// 判断是否要压缩图片
   		if(MAX_WIDTH != -1 || MAX_HEIGHT != -1) {
   			// 压缩图片
   			ImageUtil.resizeImg(resizeImg, resizeImg, MAX_WIDTH, MAX_HEIGHT);
   			
   			if(this.imgWidth > ImageUtil.ImgWidth){
   				this.imgWidth = ImageUtil.ImgWidth;
   			}
   			
   			if(this.imgHeight > ImageUtil.ImgHeight){
   				this.imgHeight = ImageUtil.ImgHeight;
   			}
   			
   			// 返回编辑器
   			out.println(insertEditor(id, saveUrl, imgTitle, imgWidth, imgHeight, imgBorder));
   		}else{
   			// 返回编辑器
   			out.println(insertEditor(id, saveUrl, imgTitle, imgWidth, imgHeight, imgBorder));
   		}				
   		
   	} catch (FileUploadException e) {
   		e.printStackTrace();
   	} catch (Exception e) {
   		e.printStackTrace();
   	}finally{
   		out.flush();
   		out.close();
   		isFlag = false;
   	}

   }

   @Override
   protected void doPost(HttpServletRequest request,
   		HttpServletResponse response) throws ServletException, IOException {
   	doGet(request, response);
   }

   /**
    * 输出打印上传失败的JSON语句
    * 
    * @param message    失败信息
    * 
    * @return 页面上传失败的JSON语句
    */
   public String alertMsg(String message) {
   	StringBuffer sb = new StringBuffer("{\"error\":\"1\",\"message\":\"");
   	sb.append(message).append("\"}");
   	return sb.toString();
   }
   
   /**
    * 输出插入图片至编辑器语句的脚本
    * 
    * @param id        编辑器ID
    * 
    * @param saveUrl   上传图片的浏览地址
    * 
    * @param imgTitle   图片的提示信息
    * 
    * @param imgWidth   设置图片的宽度
    * 
    * @param imgHeight  设置图片的宽度
    * 
    * @param imgBorder  设置图片的边框
    * 
    * @return 插入图片至编辑器的脚本语句
    */
   public String insertEditor(String id, String saveUrl, String imgTitle, 
   		int imgWidth, int imgHeight, String imgBorder){
   	StringBuffer sb = new StringBuffer("<script type\"text/javascript\">");
   	sb.append("parent.KE.plugin[\"image\"].insert(\"").append(id).append("\",\"");
   	sb.append(saveUrl).append("\",\"").append(imgTitle).append("\",\"");
   	sb.append(imgWidth).append("\",\"").append(imgHeight).append("\",\"");
   	sb.append(imgBorder).append("\");");
   	sb.append("</script>");
   	return sb.toString();
   }
   
   /**
    * 输出允许上传图片类型的数组
    * 
    * @param filesType 允许上传的图片类型
    * 
    * @return 允许上传图片类型
    */
   public String[] toArray(String filesType){
   	
   	if(filesType == null){
   		return null;
   	}
   		
   	String[] types = filesType.split(",");
   	String[] allowTypes = new String[types.length];
   	int i = 0;
   	for(String type : types){
   		allowTypes[i] = type;
   		i++;
   	}
   	
   	return allowTypes;
   }
}
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221

package com.elkan.kindeditor.upload;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Hashtable;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UploadImageManager extends HttpServlet {

   private static final long serialVersionUID = -8359652838938248988L;
   // 定义允许上传的图片的扩展名
   protected String[] FILETYPES = new String[] { "gif", "jpg", "jpeg", "png", "bmp" };
   // 定义上传图片保存目录路径
   protected String UPLOAD_PATH = "";

   public void doGet(HttpServletRequest request, HttpServletResponse response)
   		throws ServletException, IOException {
   	response.setContentType("text/html; charset=UTF-8");
   	PrintWriter out = response.getWriter();
   	String savePath = this.getInitParameter("UPLOAD_PATH");
   	if (savePath == null || savePath.isEmpty()) {
   		out.println(alertMsg("你还没设置读取上传图片保存的目录路径!"));
   		return;
   	}
   	// 图片保存目录路径
   	String rootPath = new StringBuffer(request.getSession().getServletContext().getRealPath("/")).append(savePath).toString();		
   	// 图片保存目录URL
   	String rootUrl = new StringBuffer(request.getContextPath()).append("/").append(savePath).toString();
   	//根据path参数,设置各路径和URL
   	String path = request.getParameter("path") != null ? request.getParameter("path") : "";
   	String currentPath = rootPath + path;
   	String currentUrl = rootUrl + path;
   	String currentDirPath = path;
   	String moveupDirPath = "";
   	
   	if (!"".equals(path)) {
   		String str = currentDirPath.substring(0, currentDirPath.length() - 1);
   		moveupDirPath = str.lastIndexOf("/") >= 0 ? str.substring(0, str.lastIndexOf("/") + 1) : "";
   	}

   	//排序形式,name or size or type
   	String order = request.getParameter("order") != null ? request.getParameter("order").toLowerCase() : "name";

   	//不允许使用..移动到上一级目录
   	if (path.indexOf("..") >= 0) {
   		out.println(alertMsg("不允许使用移动到上一级目录"));
   		return;
   	}
   	
   	//最后一个字符不是/
   	if (!"".equals(path) && !path.endsWith("/")) {
   		out.println("Parameter is not valid.");
   		return;
   	}
   	//目录不存在或不是目录
   	File currentPathFile = new File(currentPath);
   	if(!currentPathFile.isDirectory()){
   		out.println("Directory does not exist.");
   		return;
   	}

   	//遍历目录取的文件信息
   	List<Hashtable<?,?>> fileList = new ArrayList<Hashtable<?,?>>();
   	if(currentPathFile.listFiles() != null) {
   		for (File file : currentPathFile.listFiles()) {
   			Hashtable<String, Object> hash = new Hashtable<String, Object>();
   			String fileName = file.getName();
   			if(file.isDirectory()) {
   				hash.put("is_dir", true);
   				hash.put("has_file", (file.listFiles() != null));
   				hash.put("filesize", 0L);
   				hash.put("is_photo", false);
   				hash.put("filetype", "");
   			} else if(file.isFile()){
   				String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
   				hash.put("is_dir", false);
   				hash.put("has_file", false);
   				hash.put("filesize", file.length());
   				hash.put("is_photo", Arrays.<String>asList(FILETYPES).contains(fileExt));
   				hash.put("filetype", fileExt);
   			}
   			hash.put("filename", fileName);
   			hash.put("datetime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(file.lastModified()));
   			fileList.add(hash);
   		}
   	}

   	if ("size".equals(order)) {
   		Collections.sort(fileList, new SizeComparator());
   	} else if ("type".equals(order)) {
   		Collections.sort(fileList, new TypeComparator());
   	} else {
   		Collections.sort(fileList, new NameComparator());
   	}
   	
   	out.println(toJSONString(currentUrl, currentDirPath, moveupDirPath, fileList));
   	
   	out.flush();
   	out.close();
   }

   public void doPost(HttpServletRequest request, HttpServletResponse response)
   		throws ServletException, IOException {
   	doGet(request, response);
   }
   
   /**
    * 输出打印上传失败语句的脚本
    * 
    * @param message    失败信息
    * 
    * @return 页面打印的脚本语句
    */
   public String alertMsg(String message) {
   	StringBuffer sb = new StringBuffer("<script type\"text/javascript\">");
   	sb.append("alert(\"").append(message).append("\");");
   	sb.append("</script>");
   	return sb.toString();
   }
   
   public String toJSONString(String currentUrl, String currentDirPath, String moveupDirPath, List<Hashtable<?, ?>> fileList){
   	StringBuilder sb = new StringBuilder("{\"current_url\":\"");
   	sb.append(currentUrl).append("\",").append("\"current_dir_path\":\"");
   	sb.append(currentDirPath).append("\",\"moveup_dir_path\":\"").append(moveupDirPath).append("\",");
   	sb.append("\"file_list\":[");
   	int i = 0;
   	sb.append("{");
   	for(Hashtable<?,?> he : fileList){	
   		if(i != (fileList.size() - 1)){
   			sb.append("\"filename\":\"").append(he.get("filename")).append("\",");
   			sb.append("\"filesize\":").append(he.get("filesize")).append(",");
   			sb.append("\"filetype\":\"").append(he.get("filetype")).append("\",");
   			sb.append("\"has_file\":").append(he.get("has_file")).append(",");
   			sb.append("\"is_dir\":").append(he.get("is_dir")).append(",");
   			sb.append("\"is_photo\":").append(he.get("is_photo")).append(",");
   			sb.append("\"datetime\":\"").append(he.get("datetime")).append("\"");
   			sb.append("},{");
   		}else{
   			sb.append("\"filename\":\"").append(he.get("filename")).append("\",");
   			sb.append("\"filesize\":").append(he.get("filesize")).append(",");
   			sb.append("\"filetype\":\"").append(he.get("filetype")).append("\",");
   			sb.append("\"has_file\":").append(he.get("has_file")).append(",");
   			sb.append("\"is_dir\":").append(he.get("is_dir")).append(",");
   			sb.append("\"is_photo\":").append(he.get("is_photo")).append(",");
   			sb.append("\"datetime\":\"").append(he.get("datetime")).append("\"");
   			sb.append("}");
   		}
   		i++;
   	}
   	i = 0;
   	sb.append("],\"total_count\":").append(fileList.size()).append("}");
   	return sb.toString();
   }

   public class NameComparator implements Comparator<Object> {
   	public int compare(Object a, Object b) {
   		Hashtable<?, ?> hashA = (Hashtable<?, ?>) a;
   		Hashtable<?, ?> hashB = (Hashtable<?, ?>) b;
   		if (((Boolean) hashA.get("is_dir"))
   				&& !((Boolean) hashB.get("is_dir"))) {
   			return -1;
   		} else if (!((Boolean) hashA.get("is_dir"))
   				&& ((Boolean) hashB.get("is_dir"))) {
   			return 1;
   		} else {
   			return ((String) hashA.get("filename")).compareTo((String) hashB.get("filename"));
   		}
   	}
   }

   public class SizeComparator implements Comparator<Object> {
   	public int compare(Object a, Object b) {
   		Hashtable<?, ?> hashA = (Hashtable<?, ?>) a;
   		Hashtable<?, ?> hashB = (Hashtable<?, ?>) b;
   		if (((Boolean) hashA.get("is_dir"))
   				&& !((Boolean) hashB.get("is_dir"))) {
   			return -1;
   		} else if (!((Boolean) hashA.get("is_dir"))
   				&& ((Boolean) hashB.get("is_dir"))) {
   			return 1;
   		} else {
   			if (((Long) hashA.get("filesize")) > ((Long) hashB.get("filesize"))) {
   				return 1;
   			} else if (((Long) hashA.get("filesize")) < ((Long) hashB.get("filesize"))) {
   				return -1;
   			} else {
   				return 0;
   			}
   		}
   	}
   }

   public class TypeComparator implements Comparator<Object> {
   	public int compare(Object a, Object b) {
   		Hashtable<?, ?> hashA = (Hashtable<?, ?>) a;
   		Hashtable<?, ?> hashB = (Hashtable<?, ?>) b;
   		if (((Boolean) hashA.get("is_dir"))
   				&& !((Boolean) hashB.get("is_dir"))) {
   			return -1;
   		} else if (!((Boolean) hashA.get("is_dir"))
   				&& ((Boolean) hashB.get("is_dir"))) {
   			return 1;
   		} else {
   			return ((String) hashA.get("filetype")).compareTo((String) hashB.get("filetype"));
   		}
   	}
   }

}

呵,源码发布就到此了,上面有都有比较详细的注释文档了,相信各位可以看个明白吧。现在大家有什么自定义的功能要开发的就拿去用吧,别忘记把你开发出来的东东分享下哦,我在此恭候你的大驾光临啊,嘻嘻…… 不管你对此文章满意与否都留下个印记吧,下次用得上时好来取呀,呵。对了最后再给大家留道作业吧,怎么样把上传的附件进行分类管理呢?比如:word放到word文件夹目录………(此功能已经实现,不过公布的代码里没有,大家思考下吧,看看谁的方法最优化,呵)

答:在项目开发中一般配置Struts2的过滤映射是全部站资源,修改成只要过滤你的Struts2访问资源便可。 (现在源码公布了,你们可以把那些上传方法写到Action里面)

答:在web.xml配置上传类型是当初发布时考虑到重用性的问题,再说默认的上传文件类型应该够用了吧,只要限定大小与保存路径便可了;在JSP页面初始化编辑器定义上传文件类型是为了上传前的JS脚验证,如果说这都很麻烦,那我也没办法了。

答:这个功能还真是没有哦,我对WEB前端不是很熟悉,不过我倒是开发出表格合并的功能,目前还在测试阶段。如能开发这个图片粘贴的话就好了,不过好像要插件支持才行吧,唉,windows的东西不太好玩呀。