1.jsp页面:
<html:form method="post" action="/qlinfinter.do?o=doSavaba"
enctype="multipart/form-data">

<table width="767">
<tr>
<td width="283" height="35" align="right" class="td1 STYLE6">
审查编号:
</td>
<td class="td2 STYLE6 STYLE8">
${ip.internalNo }
</td>
</tr>
<tr>
<td width="283" height="35" align="right" class="td1 STYLE6">
申请备案部门:
</td>
<td class="STYLE6 td2">
<strong> ${ip.department } </strong>
</td>
</tr>
<tr>
<td width="283" height="35" align="right" class="td1 STYLE6">
申请备案类型:
</td>
<td class="STYLE6 td2">
<strong> ${ipr.punishClass } <input type="hidden"
name="orgId" value="${ipr.orgId }"> <input
type="hidden" name="itemId" value="${ipr.itemId }">
</strong>
</td>
</tr>
<tr>
<td width="283" height="75" align="right" valign="top"
class="td1 STYLE6">
申请备案内容描述:
</td>
<td valign="top" class="td2 STYLE6">
<span class="td2"><textarea name="opinion"
id="re" cols="70" rows="7"
style="width: 600px; height: 150px;"></textarea> </span>
</td>
</tr>
<tr>
<td width="283" height="24" align="right" valign="top"
class="td1 STYLE6">
备案报告:
</td>
<td valign="top" class="td2">
<span id="uploadFile">
文件1:

<input type="file" name="testFile[1]" size="30" class="iptCss"/><br>

</span>
</td>
</tr> <tr>
<td class="td1" width="283">&nbsp;

</td>
<td class="td2">
<input type="button" name="btnAddFile" value="添加文件"
onclick="addFile()" class="btn"/>
<input type="submit" name="btnUpload" value="提交审核" class="btn"/>
</td>
</tr>
</table>
</html:form>2.Action
public ActionForward doSavaba(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws IOException {
QlinfinterForm qlinfinterForm = (QlinfinterForm) form;
SuperviseRecord sr = qlinfinterForm.getItem4();
String orgId = request.getParameter("orgId");
String itemId = request.getParameter("itemId");
//获取表单中的文件资源
Hashtable<Object, Object> files = qlinfinterForm.getMultipartRequestHandler().getFileElements();
//遍历文件,并且循环上传
for (Enumeration<Object> e = files.keys(); e.hasMoreElements();) {

FormFile file = (FormFile) files.get((String) e.nextElement());

if (file != null && file.getFileSize() > 0) {
//使用formfile.getInputStream()来获取一个文件的输入流进行保存。

//文件名
String fileName = file.getFileName();
//文件大小
int fileSize = file.getFileSize();
//文件流
InputStream is = file.getInputStream(); //将输入流保存到文件
String rootPath = this.servlet.getServletContext().getRealPath("images\\uploads");

File f = new File(rootPath);
if (!f.exists())
f.mkdirs(); // 如果文件夹不存在,则创建

// 创建输出流
FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File(f, fileName)); byte[] b = new byte[1024];
int real = 0;
real = is.read(b);
while (real > 0) {
fos.write(b, 0, real);
real = is.read(b);
}
} catch (RuntimeException e1) {
e1.printStackTrace();
return mapping.findForward("err");
} fos.close();
is.close(); System.out.println("文件信息:");
System.out.println("\t文件名:" + fileName);
System.out.println("\t文件大小:" + fileSize);
file.destroy();

sr.setOrgId(orgId);
sr.setItemId(itemId);
sr.setSuperviseStatus("0");
sr.setSuperviseType("0");
sr.setRecordReport(fileName);
this.ql_inf_interBiz.addSuperviseRecord(sr);
}
}
PrintWriter out = response.getWriter();
out.print("<script>alert('法制监督备案申请提交成功');</script>");
out.print("<script>window.location='qlinfinter.do?o=doQlinfoBaTx'</script>");
return null;