struts2上传多个文件,下载 配制!代码
页面代码:注意,我在页面在一个新建的文件夹下(TheNameSpace)
[html]
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'uplod.jsp' starting page</title>
</head>
<body>
<h1>file upload</h1>
<s:form action="uploadList.action" enctype="multipart/form-data" theme="易做图">
<table cellpadding="0" height="5" >
<tr>
<td>用户:</td>
<td>
<s:textfield name="username"/>
</td>
</tr>
<tr>
<td>密码:</td>
<td> <s:password name="passwrod"/></td>
</tr>
<tr >
<td>文件:</td>
<td id="fileID">
<s:fielderror name="file"/>
<s:file name="file" />
<a href="javascript:addFiles()" >添加上传</a>
</td>
</tr>
<tr>
<td colspan="2">
<s:submit value="提交"/>
<s:reset value="重置"/>
</td>
</tr>
</table>
</s:form>
<script language="javascript">
function addFiles(){
var tdID=document.getElementById("fileID");
var br=document.createElement("br");
var file=document.createElement("input");
var button=document.createElement("input");
file.type="file";
file.name="file";
button.type="button";
button.value="remove";
button.onclick=function(){
tdID.removeChild(br);
tdID.removeChild(file);
tdID.removeChild(button);
}
tdID.appendChild(br);
tdID.appendChild(file);
tdID.appendChild(button);
}
</script>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'uplod.jsp' starting page</title>
</head>
<body>
<h1>file upload</h1>
<s:form action="uploadList.action" enctype="multipart/form-data" theme="易做图">
<table cellpadding="0" height="5" >
<tr>
<td>用户:</td>
<td>
<s:textfield name="username"/>
</td>
</tr>
<tr>
<td>密码:</td>
<td> <s:password name="passwrod"/></td>
</tr>
<tr >
<td>文件:</td>
<td id="fileID">
<s:fielderror name="file"/>
<s:file name="file" />
<a href="javascript:addFiles()" >添加上传</a>
</td>
</tr>
<tr>
<td colspan="2">
<s:submit value="提交"/>
<s:reset value="重置"/>
</td>
</tr>
</table>
</s:form>
<script language="javascript">
function addFiles(){
var tdID=document.getElementById("fileID");
var br=document.createElement("br");
var file=document.createElement("input");
var button=document.createElement("input");
file.type="file";
file.name="file";
button.type="button";
button.value="remove";
button.onclick=function(){
tdID.removeChild(br);
tdID.removeChild(file);
tdID.removeChild(button);
}
tdID.appendChild(br);
tdID.appendChild(file);
tdID.appendChild(button);
}
</script>
</body>
</html>
struts.xml配制文件:
[html]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">