Jquery Struts2 Upload File

【仿写】

 

1

private Logger log = Logger.getLogger(UploadFileAction.class);
	private File uploadify;
	private String uploadifyFileName;

	@SuppressWarnings("deprecation")
	public String uploadFile() throws Exception {
		String extName = "";// 扩展名
		String newFileName = "";// 新文件名
		String nowTime = new SimpleDateFormat("yyyymmddHHmmss").format(new Date());
		String savePath = ServletActionContext.getRequest().getRealPath("");
		savePath = savePath + "/uploads/";
		System.out.println(savePath);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");

		// 获取扩展名
		if (uploadifyFileName.lastIndexOf(".") >= 0) {
			extName = uploadifyFileName.substring(uploadifyFileName
					.lastIndexOf("."));
		}
		newFileName = nowTime + extName;
		uploadify.renameTo(new File(savePath + newFileName));
		response.getWriter().print(uploadifyFileName + "上传成功");
		return null; // 这里不需要页面转向,所以返回空就可以了
	}

 

 

2

<link href="css/default.css" rel="stylesheet" type="text/css" />
<link href="css/uploadify.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="scripts/swfobject.js"></script>
<script type="text/javascript" src="scripts/jquery.uploadify.v2.0.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$("#uploadify").uploadify({
		'uploader'       : 'scripts/uploadify.swf',
		'script'         : 'upload_uploadFile.action',
		'cancelImg'      : 'images/cancel.png',
		'fileDataName'   : 'uploadify',
		'folder'         : 'uploads',
		'queueID'        : 'fileQueue',
		'auto'           : true,
		'multi'          : true
	});
});

//UploadFile_uploadFile
//'/scripts/uploadify.php',
</script>
</head>

<body>
<div id="fileQueue"></div>
<input type="file" name="uploadify" id="uploadify" />
<p><a href="javascript:jQuery('#uploadify').uploadifyClearQueue()">Cancel All Uploads</a></p>
</body>

 

 

3

	<constant name="struts.devMode" value="false" />
	<constant name="struts.i18n.encoding" value="UTF-8" />
	<constant name="struts.enable.DynamicMethodInvocation" value="true" />
	<constant name="struts.i18n.reload" value="true" />
	<constant name="struts.locale" value="zh_CN" />
	<constant name="struts.url.includeParams" value="none" />
	<!-- action后缀 -->
	<constant name="struts.action.extension" value="do,action" />
	<!-- spring 集成 -->
	<constant name="struts.objectFactory.spring.autoWire" value="type" />
	<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory"/>
	<!-- 默认主题 -->
	<constant name="struts.ui.theme" value="simple" />
	<!-- 上传文件大小限制,大约90M 90000000-->
	<constant name="struts.multipart.maxSize" value="900000000" />
	
	<package name="default" namespace="/" extends="struts-default">
<action name="upload_*" class="UploadFileAction" method="{1}">
			<result name="toUpload">page/uploadFile/uploadFile.jsp</result>
			<result name="upload">page/uploadFile/upload.jsp</result>
			<result name="SUCCESS">page/right.html</result>
		</action>
	</package>

 

 

4

5

6

7

8

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值