1.单个文件上传
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ include file="../../taglibs.jsp"%>
<form:form action="/joint/disciplinary/save" modelAttribute="disciplinaryInfo" id="disciplinaryForm" method="post">
<tr>
<th>认定依据:</th>
<td>
<input type="file" style="display: none;" name="basisFile" id="basisFile" readonly="readonly" onchange="checkFile('basisFile','basis')"/>
<input name="basis" class="f-w200 u-ipt" readonly="readonly" />
<input type="button" value="选择文件" onclick="basisFile.click();" class="u-btn u-btn-02 js-add" />
</td>
</tr>
<tr>
<th>报送函:</th>
<td>
<input type="file" style="display: none;" name="reportFile" id="reportFile" readonly="readonly" onchange="checkFile('reportFile','report')"/>
<input name="report" class="f-w200 u-ipt" readonly="readonly" />
<input type="button" value="选择文件" onclick="reportFile.click();" class="u-btn u-btn-02 js-add" />
</td>
</tr>
</table>
<div class="btn-box">
<input class="u-btn" id="form_save" type="submit" value="保存">
<input class="u-btn u-btn-03" type="reset" onclick="javascript:history.go(-1)" value="返回">
</div>
</form:form>
</div>
<script type="text/javascript" src="${ctx}/js/webuploader/webuploader.min.js"></script>
<script type="text/javascript" src="${ctx}/js/webuploader/image-upload/upload.js"></script>
<script type="text/javascript">
/**
* 检查上传文件类型
*/
function checkFile(id,inputId) {
var filePath = $("#"+id).val();
if (filePath != null && filePath != '') {
var f = filePath.split('.');
if (f[f.length - 1] == 'pdf' || f[f.length - 1] == 'gif' || f[f.length - 1] == 'jpeg' || f[f.length - 1] == 'png') {
//展示文件路径
$("#"+inputId).val(filePath);
} else {
//删除file标签中文件信息,不展示文件路径
$("#"+id).val("");
layer.alert("请选择pdf文件或图片");
return;
}
} else {
layer.alert("请选择文件");
return;
}
}
</script>
public class DisciplinaryInfo{
/** @Fields reportFilePath: 报送函路径*/
private String reportFilePath;
/** @Fields reportFile:上传文件-报送函*/
private MultipartFile reportFile;
/** @Fields basisFile:上传文件-认定依据*/
private MultipartFile basisFile;
/** @Fields basisFileName: 认定依据名称*/
private String basisFileName;
}
2.多种文件与其他信息一起保存