使用struts2实现多文件上传源码
来源:互联网 发布:maya软件上色 编辑:程序博客网 时间:2024/05/22 20:10
开发环境:
myeclipse6.5+tomcat+6.0+jdk1.6
Register.java
package controller;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class Register extends ActionSupport {
private String username;
private File uploadFile[]; //是File的数组类型
private String uploadFileFileName[];//由于上传多个文件,所以文件名也是数组类型
@Override
public void validate()
{
}
public void setUsername(String username)
{
this.username=username;
}
public File[] getUploadFile()
{
return uploadFile;
}
public void setUploadFile(File[] uploadFile)
{
this.uploadFile=uploadFile;
}
public String[] getUploadFileFileName()
{
return uploadFileFileName;
}
public void setUploadFileFileName(String[] uploadFileFileName)
{
this.uploadFileFileName=uploadFileFileName;
}
public String execute() throws IOException
{
System.out.println("username的值是:"+username);
String targetDirectory=ServletActionContext.getRequest().getRealPath("/upload");
for(int i=0;i<uploadFile.length;i++)
{
File target=new File(targetDirectory,new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()).toString()+System.nanoTime()+uploadFileFileName[i]);
FileUtils.copyFile(uploadFile[i], target);
}
return "register";
}
}
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="struts3.1" extends="struts-default">
<action name="register" class="controller.Register">
<result name="register">/showregister.jsp</result>
<result name="input">/register.jsp</result>
</action>
</package>
<constant name="struts.ui.theme" value="simple"></constant>
</struts>
register.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page isELIgnored="false" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>我爱编程网</title>
</head>
<body>
<s:form action="register" method="post" enctype="multipart/form-data">
username:<s:textfield name="username"></s:textfield>
<br/>
<s:file name="uploadFile"></s:file>
<br/>
<s:file name="uploadFile"></s:file>
<br/>
<s:file name="uploadFile"></s:file>
<br/>
<s:submit value="提交"></s:submit>
</s:form>
</body>
</html>
showregister.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>我爱编程网</title>
</head>
<body>
上传成功!
</body>
</html>
- 使用struts2实现多文件上传源码
- struts2实现文件上传源码
- Struts2实现多文件上传
- Struts2实现多文件上传
- struts2实现多文件上传
- Struts2实现多文件上传
- Struts2实现多文件上传
- Struts2实现多文件上传
- Struts2实现多文件上传
- Struts2实现多文件上传
- Struts2实现多文件上传
- struts2实现多文件上传
- Struts2实现多文件上传
- Struts2 实现多文件上传
- 使用struts2和uploadify实现多文件上传
- 使用Struts2标签实现文件上传
- 使用struts2如何实现文件上传
- Struts2实现文件上传
- c函数声明 左右法则
- .net 2.0使用ajax
- 起笔
- JVM中的out of memory错误原因
- Hibernate 3与2
- 使用struts2实现多文件上传源码
- 日语能力考试介绍
- 关于汇编里面的PTR
- struts2实现文件上传源码
- C#(.net)中的DllImport
- 警务态势模板中配置服务器端口
- WebObjects的配置问题
- 在window里面套一个form,form里面fieldset,fieldset里面的控件如果给了ID,就出问题
- .Net Lambda