uploadify与struts2

我使用的uploadify版本为3.2.1,整合SSH+uploadify

需要的文件有:

jquery-1.7.2.js(注意:这个文件是我自己单独下载的,uploadify文件夹里没有)

jquery.uploadify.js

jquery.uploadify.min.js

uploadify-cancel.png

uploadify.css

uploadify.swf

前台html代码:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="uploadify/jquery.uploadify.js"></script>
<script type="text/javascript" src="uploadify/jquery.uploadify.min.js"></script>
<link rel="stylesheet" type="text/css" href="uploadify/uploadify.css">	
</head>

<script type="text/javascript">
$(function () {
    $('#uploadify').uploadify({
        uploader: 'upload!uploadFile',           // 服务器端处理地址
        swf: '/uploadify/uploadify.swf',    // 上传使用的 Flash
        width: 60,                          // 按钮的宽度
        height: 23,                         // 按钮的高度
        buttonText: "上传",                 // 按钮上的文字
        buttonCursor: 'hand',                // 按钮的鼠标图标
        fileObjName: 'uploadify',            // 上传参数名称 后台action里面的属性uploadify
        // 两个配套使用
        fileTypeExts: "*.jpg;*.png;*.txt",             // 扩展名
        fileTypeDesc: "请选择 jpg png txt 文件",     // 文件说明
        auto: false,                // 选择之后,自动开始上传
        multi: true,               // 是否支持同时上传多个文件
        queueSizeLimit: 5          // 允许多文件上传的时候,同时上传文件的个数
    });
});
</script>
<body>
        <input type="file" name="uploadify" id="uploadify" />
        <a href="javascript:$('#uploadify').uploadify('cancel')">清除第一个文件</a>
        <a href="javascript:$('#uploadify').uploadify('cancel', '*')">清除所有文件</a>
        <a href="javascript:$('#uploadify').uploadify('upload', '*')">上传所有文件</a>
</body>
   </html>


后台action代码

package com.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.ParentPackage;
import com.hhkj.tjsjbz.util.PublicOPCode;
import com.opensymphony.xwork2.ActionSupport;

@ParentPackage("framework-package")
public class UploadAction extends ActionSupport{
	
	private File uploadify;
	private String uploadifyFileName;

	public String uploadFile() throws IOException{
		String savePath = ServletActionContext.getServletContext().getRealPath("/uploads/");//上传完后文件存放位置
		System.out.println(savePath);
		String newsuffix = "";
		String current=PublicOPCode.getcurrentdate();
		if((uploadifyFileName != null)&&(uploadifyFileName.length()>0))
		{
			int dot = uploadifyFileName.lastIndexOf(".");
			if((dot >-1) && (dot < (uploadifyFileName.length() - 1)))
			{
				 newsuffix = uploadifyFileName.substring(dot + 1);
			}
		}
		FileInputStream fis = new FileInputStream(uploadify);
		FileOutputStream fos = new FileOutputStream(savePath+"/"+ current + "." + newsuffix);
		IOUtils.copy(fis, fos);
		fos.flush();
		fos.close();
		fis.close();
		return null;
	}
	
	public File getUploadify() {
		return uploadify;
	}
	public void setUploadify(File uploadify) {
		this.uploadify = uploadify;
	}
	public String getUploadifyFileName() {
		return uploadifyFileName;
	}
	public void setUploadifyFileName(String uploadifyFileName) {
		this.uploadifyFileName = uploadifyFileName;
	}
	
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值