Ajax File Upload - For Struts 2

这是文章出处:http://www.davidjc.com/ajaxfileupload/demo!input.action

另外可参考这篇文章:http://www.struts2.org/ajax-file-upload-in-struts2-using-ajax-file-upload-plugin/

在http://ajax-file-upload-struts2.googlecode.com/files/AjaxFileUpload-0.03.zip 下载包文件

把jar文件加入到 WEB-INF/lib下面,在pom.xml中加入:

<dependency>
	<groupId>commons-fileupload</groupId>
	<artifactId>commons-fileupload</artifactId>
	<version>1.2</version>
</dependency>
<dependency>
	<groupId>commons-io</groupId>
	<artifactId>commons-io</artifactId>
	<version>1.3.1</version>
</dependency>
<dependency>
	<groupId>net.sf.json-lib</groupId>
	<artifactId>json-lib</artifactId>
	<version>2.0</version>
	<classifier>jdk15</classifier>
</dependency>

 在所在的jsp页面如下写法:

<%@ taglib uri="http://www.davidjc.com/taglibs"     prefix="djc"     %>
<head>
	...
	<djc:head />
	...
</head>
<body>
	...
	<djc:ajaxfileuploadform action="demo" dobefore="" doafter="" />
	...
</body>

 配置struts.xml文件:

<package name="ajaxfileupload" namespace="/" extends="ajaxfileupload-default">
	<action name="demo" class="com.davidjc.ajaxfileupload.action.Demo">
		<interceptor-ref name="fileUploadStack" /> 
		
		<result name="success" type="httpheader">
			<param name="status">200</param>
		</result>
	</action>
</package>

 扩展 action  com.davidjc.ajaxfileupload.action.FileUpload

package com.davidjc.ajaxfileupload.action;

import java.io.File;
import org.apache.log4j.Logger;
import com.opensymphony.xwork2.Action;

public class Demo extends FileUpload{

    private final Logger logger = Logger.getLogger(Demo.class);

    public String execute() {
	File uploadedFile = this.getUpload();
	String contentType = this.getUploadContentType();
	String fileName = this.getUploadFileName();
	

	return Action.SUCCESS;	
    }
    
}
 

 

你可能感兴趣的:(json,xml,log4j,Ajax,struts)