<%@ page contentType="text/html; charset=gb2312" language="java" %><%@ include file="checkloginc.jsp"%><%@ page import="com.jspsmart.upload.*"%><%@ page import="java.util.Date"%><%@ page import="java.text.*"%><jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" /><HTML><BODY BGCOLOR="white"><%//作者:Arhwen email:arhwen@126.com //生成日期字符串,以便产生一个不会重复的文件名 SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddhhmmss"); Date myDate = new Date(); String tempname=formatter.format(myDate);// 上传初始化 mySmartUpload.initialize(pageContext); mySmartUpload.setTotalMaxFileSize(10000000); // 允许上传的文件类型 mySmartUpload.setAllowedFilesList("jpg,gif,png,asf,wmv,avi,swf,txt,rar"); // 禁止上传的文件类型: mySmartUpload.setDeniedFilesList("exe,bat,jsp,asp,php,aspx"); // 上传 mySmartUpload.upload();try { //获得表单与输入框名称 String formname,fieldname; formname=request.getParameter("formname"); fieldname=request.getParameter("fieldname"); //改名开始 File myfile = mySmartUpload.getFiles().getFile(0); String filename = null; if (myfile .getFileExt().length()>0){ String temp_FileName = "arhwen_"+fieldname+"_"+tempname;//这儿在日期字符串加上了一个标识符 myfile .saveAs("/upload/"+temp_FileName+"."+myfile.getFileExt(),mySmartUpload.SAVE_VIRTUAL); filename =temp_FileName+"."+myfile .getFileExt(); }//改名结束 //将生成的文件名自动写在文本框 out.print("<script>window.opener.document."+formname+"."+fieldname+".value='"+filename+"'</script>"); } catch (Exception e) { out.println(e.toString()); } %></BODY></HTML>