利用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/
利用iframe实现无刷新上传处理的更多相关文章
- .net MVC借助Iframe实现无刷新上传文件
html: <div id="uploadwindow" style="display: none;"> <form action=" ...
- jquery 无刷新上传的小function
function zll_up(click_id,up_url,text_id,show_id){ this.create = function(){} //当点击指定元素时,创建iframe for ...
- ajax +jsp+iframe无刷新上传文件[转]
http://hi.baidu.com/zj360202/blog/item/f23e3711f929c774cb80c475.html ajax jsp 无刷新上传文件 2009-10-26 16: ...
- web 开发之js---巧用iframe实现jsp无刷新上传文件
首先要说的就是 ajax 是无法实现上传文件的,可以想一下ajax与后台通信都是通过传递字符串,怎么能传递文件呢?其实出于安全考虑js是不能操作文件的,所以就不要再说用ajax来实现文件的上传了,这是 ...
- jQuery无刷新上传学习心得
记得刚离开大学,进入目前这家公司不到一个月时,有一位前辈给我们当时的新人讲了下JS无刷新上传的相关知识. 在此之前,一直都是在使用C#提供的服务器上传控件FileUpload,但是每次使用时,都会刷新 ...
- js实现无刷新上传
在新增数据项的时候,用ajax实现无刷新提交,但上传文件的时候,由于数据类型原因,不能将页面的<asp:FileUpload>中以字符串值的方式传到js里调用.我一共找到了两个方法予以解决 ...
- ajax 无刷新上传
最近要做微信的图文上传,因为一个图文了表中可以有多个图文,所有按钮需要随时添加,所以做了一种无刷新上传的方法. 首先我们要在html页面中写上这样的几段代码 javascript: $(functio ...
- [Asp.net mvc]jquery.form.js无刷新上传
写在前面 最近在自己的网盘项目中想用ajax.beginform的方式做无刷新的操作,提交表单什么的都可以,但针对文件上传,就是个鸡肋.在网上查找了发现很多人都遇到了这个问题,大部分都推荐使用jque ...
- 基于h5的图片无刷新上传(uploadifive)
基于h5的图片无刷新上传(uploadifive) uploadifive简介 了解uploadify之前,首先了解来一下什么是uploadify,uploadfy官网,uploadify和uploa ...
随机推荐
- iis7 压缩js文件和启用gzip压缩
压缩js文件 打开IIS 7的配置文件:c:\windows\system32\inetsrv\config\applicationhost.config 在<staticContent loc ...
- 修复 XE7 update1 发布 iOS 8.x 实机问题
1. 开启工程目录下面的 Entitlement.TemplateiOS.xml 档案. 2. 加入二行: <key>application-identifier</key> ...
- java.lang.NoSuchMethodError: org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar
今天在服务器部署的时候,发生了这个问题,明明在本机上使用的时候,没有发生错误,但是发布到服务器上的时候却发生了这个错误,百度了好久,发现遇到这个问题的人很多,但是却没有一个比较满意的答案,后来还是通过 ...
- 2016暑假多校联合---Another Meaning
2016暑假多校联合---Another Meaning Problem Description As is known to all, in many cases, a word has two m ...
- Atom + activate-power-mode震屏插件Windows7下安装
Atom是Github推出的一个文本编辑器,搜索一下大概是给Web前端用的,最近比较火的是他的一个插件activate-power-mode,可以实现打字屏振效果. 用来装装逼还是挺适合的,本来想试试 ...
- GJM : Python简单爬虫入门(二) [转载]
感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...
- GJM : Unity3D - NetWork - Hight Level API ( HLAPI) [转载]
介绍在本系列教程中,我们将使用的网络高级API(HLAPI)来构建一个小型的多人网络案例.即使我们的例子很简单,但也会涵盖以下关键概念,这应该可以帮助大家使用HLAPI构建大型游戏项目. 在第一部分, ...
- Play!中使用HTTP异步编程
本章译者:@Sam Liu (译者未留下自己的主页,请Sam Liu见此文,加入群168013302联系‘大黄蜂@翻译play’) 这一章主要讲解如何运用异步模式实现典型的长连接(long-polli ...
- 优秀工具推荐:两款很棒的 HTML5 游戏开发工具
HTML5 众多强大特性让我们不需要多么高深技术就能创建好玩的网页游戏,同时证明了开放的 Web 技术能与任何其他在游戏开发中使用的技术竞争.正如标题所说,这篇文章推荐的几款很棒 HTML5 游戏开发 ...
- css中white-space的值pre-wrap
CSS中white-space属性设置如何处理元素内的空白.默认值normal表示:空白会被浏览器忽略. white-space这个属性声明建立布局过程中如何处理元素中的空白符.值 pre-wrap ...