< %@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
< %@ taglib prefix="s" uri="/struts-tags" %>
< %
String path = request.getContextPath();
pageContext.setAttribute("context",path);
%>
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
</meta><meta http-equiv="cache-control" content="no-cache">
</meta><meta http-equiv="expires" content="0">
</meta><meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
</meta><meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function more() {
var td = document.getElementById("more");
var br = document.createElement("br");
var input = document.createElement("input");
input.type="file";
input.name="uf.upload";
var button = document.createElement("input");
button.type="button";
button.value="remove";
td.appendChild(br);
td.appendChild(input);
td.appendChild(button);
button.onclick = function() {
td.removeChild(br);
td.removeChild(input);
td.removeChild(button);
}
}
</script>
</meta></head>
<body>
<h1>
struts2上传不定数的文件,限制文件上传类型(struts.xml配置拦截器)
</h1>
<hr />
<s :fielderror></s>
<table align="center" border="1" width="50%">
<s :form action="upload" enctype="multipart/form-data" method="post" theme="simple">
<tr>
<td>
用户名:
</td>
<td>
<s :textfield name="uf.username"></s>
</td>
</tr>
<tr>
<td>
上传:
</td>
<td id="more">
<s :file name="uf.upload"></s><font color="red">*只能上传.jpg文件,小于400kb</font>
<input type="button" value="添加.." onclick="more()"/>
</td>
</tr>
<tr> <td align="center">
<s :submit value="提交"></s>
</td>
<td><s :reset value="重置"/></td>
</tr>
</s>
</table>
</body>
</html>