三、struts2+swfUpload简单例子

阅读更多
下面是效果介绍:
三、struts2+swfUpload简单例子_第1张图片

三、struts2+swfUpload简单例子_第2张图片

项目目录截图:
三、struts2+swfUpload简单例子_第3张图片

代码介绍

1、Index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



  
  
   	
   	
    
    
   	
   
  
  
  

文件上传



Upload.action

package com.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class FileUploadAction extends ActionSupport {
	private File file;
	private String fileFileName;
	private String fileContentType;
	private String savePath;

	public String execute() throws Exception {
		
		InputStream is = new FileInputStream(file);
		String root = getSavePath();
		//String tempName = System.currentTimeMillis()+this.getFileFileName().substring(this.getFileFileName().indexOf("."));	
		File deskFile = new File(root, this.getFileFileName());
		OutputStream os = new FileOutputStream(deskFile);
		byte[] bytefer = new byte[1024];
		int length = 0;
		while ((length = is.read(bytefer)) != -1) {
			os.write(bytefer, 0, length);
		}
		os.close();
		is.close();
		return "success";
	}

	
	public String getSavePath() {
		return ServletActionContext.getServletContext().getRealPath(savePath);
	}


	public void setSavePath(String savePath) {
		this.savePath = savePath;
	}


	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	public String getFileFileName() {
		return fileFileName;
	}

	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}

	public String getFileContentType() {
		return fileContentType;
	}

	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}

}



Web.xml


	
		index.jsp
	
	
		struts2
		
			org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
	
	
		struts2
		/*
	




Struts.xml




	
	
	
	
	
	
	
		
			/upload
			/index.jsp
			/index.jsp
		
	


官方站点: http://www.swfupload.org/
DEMO地址: http://demo.swfupload.org/


SWFUplaod学习笔记阅读顺序
一、了解SWFUpload 
http://hanxin0311.iteye.com/blog/1915611

二、详细介绍SWFUpload
http://hanxin0311.iteye.com/blog/1915615

三、struts2+swfUpload简单例子
http://hanxin0311.iteye.com/blog/1915626

四、struts2+swfUpload深度整合
http://hanxin0311.iteye.com/blog/1915628

SWFUpload像服务器传递参数
http://hanxin0311.iteye.com/blog/1913946

SWFUpload接受服务器Action返回的参数
http://hanxin0311.iteye.com/blog/1915644

SWFUpload中文乱码问题
http://hanxin0311.iteye.com/blog/1915648


附件提供代码下载

项目开发工具 myeclipse8.5  下载代码 (如果附件不能下载点击此处下载)
  • 三、struts2+swfUpload简单例子_第4张图片
  • 大小: 4.8 KB
  • 三、struts2+swfUpload简单例子_第5张图片
  • 大小: 24 KB
  • 三、struts2+swfUpload简单例子_第6张图片
  • 大小: 26.1 KB
  • struts2SwfUpload.zip (6.8 MB)
  • 下载次数: 686
  • 查看图片附件

你可能感兴趣的:(struts2,swfUpload,例子,demo)