`
xwl1991
  • 浏览: 12812 次
  • 性别: Icon_minigender_1
  • 来自: 湖南
最近访客 更多访客>>
社区版块
存档分类
最新评论

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

 

 

 

 

 

 

 

 

  • file.7z (50.2 KB)
  • 下载次数: 1
分享到:
评论

相关推荐

    easyUi+jquery+common-file-upload +struts2带进度条的文件上传DEMO

    基于eclipse + easyUi1.2.6+common-fileupload + struts2实现带进度条的文件上传DEMO,具体效果跟思路可见我的博客:http://blog.csdn.net/jun55xiu/article/details/22042279

    JQuery_uploadify_struts2_jsp__ajax多文件上传

    'fileDataName' : 'file' 因为在页面上没有加上这个属性,导致在aciton里边接收不到file文件,页面会显示:HTTP ERROR! &lt;result name="upload" type="dispatcher"&gt; /index.jsp return "upload"; 开始我这里...

    AjaxFileUpload+Struts2实现多文件上传功能

    本文重点给大家介绍AjaxFileUpload+Struts2实现多文件上传功能,具体实现代码大家参考下本文。 单文件和多文件的实现区别主要修改两点, 一是插件ajaxfileupload.js里接收file文件ID的方式 二是后台action是数组形式...

    兼容ie8,9,10能够正确返回json结果的ajaxfileupload.js

    struts2+jquery+ajaxfileupload 需要正确配置struts2文件struts-xml文件中需要配置extends="json-default"。如果返回json结果需要在前台js中解析json数据,要用jquery的jQuery.parseJSON(json)。

    jquery ajaxfileupload异步上传插件

    服务器端采用struts2来处理文件上传。 所需环境: jquery.js ajaxfileupload.js struts2所依赖的jar包 及struts2-json-plugin-2.1.8.1.jar 编写文件上传的Action package com.ajaxfile.action; import java.io....

Global site tag (gtag.js) - Google Analytics