效果图:
 

代码:

 
  
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%@taglib prefix="s" uri="/struts-tags"%>  
  3. <%  
  4. String path = request.getContextPath();  
  5. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  6. %>  
  7.  
  8. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  9. <html>  
  10. <head>  
  11. <base href="<%=basePath%>">  
  12.  
  13. <title>My JSP 'upload.jsp' starting page</title>  
  14.  
  15. <script type="text/javascript">  
  16. function AddMore(){  
  17. var more = document.getElementById("file");  
  18. var br = document.createElement("br");  
  19. var input = document.createElement("input");  
  20. var button = document.createElement("input");  
  21.  
  22. input.type = "file";  
  23. input.name = "file";  
  24.  
  25. button.type = "button";  
  26. button.value = "删除";  
  27.  
  28. more.appendChild(br);  
  29. more.appendChild(input);  
  30. more.appendChild(button);  
  31.  
  32. button.onclick = function(){  
  33. more.removeChild(br);  
  34. more.removeChild(input);  
  35. more.removeChild(button);  
  36. };   
  37. }  
  38. </script>  
  39. </head>  
  40.  
  41. <body>  
  42. <s:form action="upload" method="post" theme="simple" enctype="multipart/form-data">  
  43. <table border="1" width="50%">  
  44. <tr>  
  45. <td>用户名:</td>  
  46. <td><s:textfield name="username" label="用户名"></s:textfield></td>  
  47. </tr>  
  48. <tr>  
  49. <td>附件:</td>  
  50. <td id="file">  
  51. <s:file name="file" label="文件"></s:file>  
  52. <input type="button" value="增加附件" οnclick="AddMore()">  
  53. </td>  
  54. </tr>  
  55. <tr>  
  56. <td colspan="2" align="center">  
  57. <s:submit value="提交" ></s:submit></td>  
  58. </tr>  
  59. </table>   
  60. </s:form>  
  61. </body>  
  62. </html>