效果图:
代码:
- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <%@taglib prefix="s" uri="/struts-tags"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>My JSP 'upload.jsp' starting page</title>
- <script type="text/javascript">
- function AddMore(){
- var more = document.getElementById("file");
- var br = document.createElement("br");
- var input = document.createElement("input");
- var button = document.createElement("input");
- input.type = "file";
- input.name = "file";
- button.type = "button";
- button.value = "删除";
- more.appendChild(br);
- more.appendChild(input);
- more.appendChild(button);
- button.onclick = function(){
- more.removeChild(br);
- more.removeChild(input);
- more.removeChild(button);
- };
- }
- </script>
- </head>
- <body>
- <s:form action="upload" method="post" theme="simple" enctype="multipart/form-data">
- <table border="1" width="50%">
- <tr>
- <td>用户名:</td>
- <td><s:textfield name="username" label="用户名"></s:textfield></td>
- </tr>
- <tr>
- <td>附件:</td>
- <td id="file">
- <s:file name="file" label="文件"></s:file>
- <input type="button" value="增加附件" οnclick="AddMore()">
- </td>
- </tr>
- <tr>
- <td colspan="2" align="center">
- <s:submit value="提交" ></s:submit></td>
- </tr>
- </table>
- </s:form>
- </body>
- </html>
转载于:https://blog.51cto.com/huqianhao/954843