利用iframe实现无刷新上传处理

继上一篇对上传异常进行处理之后,当上传异常的时候的错误体验并不是很好,这里介绍用iframe来进行错误提示

拦截错误

@ExceptionHandler(MaxUploadSizeExceededException.class)
public String handleException(Exception ex,HttpServletRequest request,HttpServletResponse response) {
try {
if (ex instanceof org.springframework.web.multipart.MaxUploadSizeExceededException){
request.setAttribute("msg", "图片的总计大小不能超过50M ");
}
} catch (Exception e) {
e.printStackTrace();
}
// return "redirect:/sales/apply/onLodaImageUplod.do?mspNo="+mspNo;
return "views/sales/apply/a_image_uploading_error";


控制器

@RequestMapping(value = "/sales/apply/imageUploding")
public String imageUploding(String mspNo, HttpServletRequest request,
HttpServletResponse response , PrintWriter write
,@RequestParam("chargeFront") CommonsMultipartFile chargeFront
,@RequestParam("applicantIdFront") CommonsMultipartFile applicantIdFront
,@RequestParam("applicantIdSide") CommonsMultipartFile applicantIdSide
,@RequestParam("insuredsIdFront") CommonsMultipartFile insuredsIdFront
,@RequestParam("insuredsIdSide") CommonsMultipartFile insuredsIdSide
,Model model
)
{
//逻辑处理代码

return "views/sales/apply/a_image_uploading_error";
}


a_image_uploading.jsp


<form action="${ctx}sales/apply/imageUploding.do?applyBarCode=${applyBarCode}&mspNo=${mspNo}" method="post" id="fm" enctype="multipart/form-data">
<table border="0" cellspacing="0" cellpadding="0" class="T1" width="100%">
<tr>
<td colspan="4" style="font-size: 12px;color: red;">
<span style="margin-left: 20%">
提示:影像仅支持JPG格式,且单张图片不能超过5M,影像上传过程中,切勿关闭页面,谢谢。
</span>
</td>
</tr>
<tr height="35px">
<td width="35%" align="right"> 缴费卡照片:</td>
<td width="65%">
<input type="file" name="chargeFront" id="chargeFront" onchange="onchangeFileImage(this.value,'chargeFrontSpanId')"/>
<span id="chargeFrontSpanId" style="color: red">${requestScope.bytesMap['chargeFrontMessage']}</span>
</td>
</tr>
</form>
</div>
<iframe name="frame" style="display:none"></iframe>
<p class="tac" style="padding: 5px;">
<span id="hint" style="font-size: 12px;color: red;"></span>
</p>
<p class="tac" style="padding: 5px;">
<a href="#" id="imageUploading" class="m_l10 btn btn_redV" >下一步</a>
</p>
</div>



$("#imageUploading").click(function() {
document.getElementById('hint').innerHTML = '<span id="hint" style="font-size: 12px;color: red;"></span>';
if(checkoutImage()){
var bln = window.confirm("进入自核后,您录入的投保信息以及拍摄的资料将无法再修改,是否继续?");
document.forms['fm'].target = 'frame';
if(bln){
//showUploadBlock();
//showBlock();
$("#fm").submit();
}
}
});


a_image_uploading_error.jsp

<script type="text/javascript">
window.onload = function(){
//移除遮罩层
window.parent.hideBlock();
var mspNo = document.getElementById('mspNostr').value;
// 本页面获得的提示信息
if(document.getElementById('subhint'))
{
var hint = document.getElementById('subhint').innerHTML;
// 找到父页面
if(window.parent){
if(window.parent.reset){
window.parent.reset();
}
if(window.parent.document.getElementById('hint')){
window.parent.location.reload();
window.parent.document.getElementById('hint').innerHTML = hint;
}
}
}

if(mspNo)
{
window.parent.location.href = "${ctx}/sales/apply/ownCheck.do?mspNo="+mspNo;
}
}
</script>


</body>
<span id="subhint">${msg}</span>
<input type="hidden" id="mspNostr" value="${mspNo}">


博客地址:http://qiaoyihang.iteye.com/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值