继上一篇对上传异常进行处理之后,当上传异常的时候的错误体验并不是很好,这里介绍用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/

利用iframe实现无刷新上传处理的更多相关文章

  1. .net MVC借助Iframe实现无刷新上传文件

    html: <div id="uploadwindow" style="display: none;"> <form action=" ...

  2. jquery 无刷新上传的小function

    function zll_up(click_id,up_url,text_id,show_id){ this.create = function(){} //当点击指定元素时,创建iframe for ...

  3. ajax +jsp+iframe无刷新上传文件[转]

    http://hi.baidu.com/zj360202/blog/item/f23e3711f929c774cb80c475.html ajax jsp 无刷新上传文件 2009-10-26 16: ...

  4. web 开发之js---巧用iframe实现jsp无刷新上传文件

    首先要说的就是 ajax 是无法实现上传文件的,可以想一下ajax与后台通信都是通过传递字符串,怎么能传递文件呢?其实出于安全考虑js是不能操作文件的,所以就不要再说用ajax来实现文件的上传了,这是 ...

  5. jQuery无刷新上传学习心得

    记得刚离开大学,进入目前这家公司不到一个月时,有一位前辈给我们当时的新人讲了下JS无刷新上传的相关知识. 在此之前,一直都是在使用C#提供的服务器上传控件FileUpload,但是每次使用时,都会刷新 ...

  6. js实现无刷新上传

    在新增数据项的时候,用ajax实现无刷新提交,但上传文件的时候,由于数据类型原因,不能将页面的<asp:FileUpload>中以字符串值的方式传到js里调用.我一共找到了两个方法予以解决 ...

  7. ajax 无刷新上传

    最近要做微信的图文上传,因为一个图文了表中可以有多个图文,所有按钮需要随时添加,所以做了一种无刷新上传的方法. 首先我们要在html页面中写上这样的几段代码 javascript: $(functio ...

  8. [Asp.net mvc]jquery.form.js无刷新上传

    写在前面 最近在自己的网盘项目中想用ajax.beginform的方式做无刷新的操作,提交表单什么的都可以,但针对文件上传,就是个鸡肋.在网上查找了发现很多人都遇到了这个问题,大部分都推荐使用jque ...

  9. 基于h5的图片无刷新上传(uploadifive)

    基于h5的图片无刷新上传(uploadifive) uploadifive简介 了解uploadify之前,首先了解来一下什么是uploadify,uploadfy官网,uploadify和uploa ...

随机推荐

  1. pageEncoding的默认设置

    windows-->preference-->myeclipse-->files and editors-->jsp 右侧 Encoding 选择  ISO 10646/Uni ...

  2. objective-c 宏定义UIAlertController公用方法

    IOS的方法经常都有更迭,以前弹出框使用 AlertView,现在使用UIAlertController AlertView的宏定义 #define showMessage(__MESSAGE__) ...

  3. 蘑菇街2015校招 Java研发笔试题 详解

    1. 对进程和线程描述正确的是( ) A.  父进程里的所有线程共享相同的地址空间,父进程的所有子进程共享相同的地址空间. B.  改变进程里面主线程的状态会影响其他线程的行为,改变父进程的状态不会影 ...

  4. java 克隆

    1. About Java中, 对于基本数据类型可以使用"=" 来克隆,此时两个对象除了相等是没有任何关系的; 而对于引用类型, 却不能简单地使用"="来克隆, ...

  5. C语言Scanf函数

    C语言的scanf函数 一.变量的内存分析 (一)字节与地址 ①. 内存以字节为单位 每个字节都有自己的内存地址,根据地址就可以找到该字节.整个内存相当于一整个酒店,而酒店以房间为单位,在这里每个房间 ...

  6. TestNG官方文档中文版(2)-annotation

    TestNG的官方文档的中文翻译版第二章,原文请见 http://testng.org/doc/documentation-main.html 2 - Annotation 这里是TestNG中用到的 ...

  7. Java继承中成员方法的overload(重载/过载)

    如果Java基础类有一个方法名被"过载"使用多次,在衍生类里对那个方法名的重新定义就不会隐藏任何基础类的版本.所以无论方法在这一级还是在一个基础类中定义,过载都会生效. publi ...

  8. Git修改提交的用户名和Email

    git config --global user.name "Your Name" git config --global user.email you@example.com

  9. io.js - 兼容 NPM 平台的 Node.js 新分支

    io.js(JavaScript I/O)是兼容 NPM 平台的 Node.js 新分支,由 Node.js 的核心开发者在 Node.js 的基础上,引入更多的 ES6 特性,它的目的是提供更快的和 ...

  10. React Native——我的学习套路

    学习东西都有一定的套路,特别是新的框架,对于React Native,我是这么学的. 第一步 : 这是啥 在各种原因下,需要使用某个框架时,那第一件事就是知道这个框架是用来干什么.React Nati ...