EasyUI 结合spring MVC上传图片以及验证图片是否符合规范
来源:互联网 发布:什么软件可以下载图片 编辑:程序博客网 时间:2024/06/09 18:11
近期正在学习使用EasyUI,EasyUI结合spring MVC上传图片以及验证上传文件是否符合规范,直接上代码:
jsp页面部分代码:
<form id="group-form" action="<c:url value='/group/create-or-update'/>" method="post" enctype="multipart/form-data"><tr><td>Logo:</td><td><input name="logo" id="logoFile" class="easyui-filebox"></input></td></tr></form>
$(function() { $( '#logoFile') .filebox( { onChange : function() { var name = $( '#logoFile').filebox( 'getValue'); var allowExtention = new Array("jpg", "png" ); var len = name.length; var math = name.substring(len - 3, len); Boolean f = false; for ( var i = 0; i < allowExtention.length; i++) { if (allowExtention[i] == math) { f = true; } } if ($.trim(name) != "" && f == false) { alert( '请选择jpg、png图片' ); $( '#logoFile').filebox( 'clear') } } }); });
Spring MVC Control层代码
@RequestMapping(value = "/create", produces = "application/json;charset=UTF-8")@ResponseBodypublic void create(HttpServletRequest request, @RequestParam(value="logo", required=false) MultipartFile logo) throws IllegalStateException, IOException {<pre name="code" class="html"> String uPath = (String)request.getServletContext().getAttribute("uPath"); File dir = new File(uPath + logo_path);//存放图片路径<span style="white-space:pre"></span> if(!dir.exists()) { dir.mkdirs(); } if(logo != null && !logo.isEmpty()) { int index = logo.getOriginalFilename().lastIndexOf('.'); String picName = DigestUtils.md5Hex(group.getId().toHexString()) + logo.getOriginalFilename().substring(index); logo.transferTo(new File(uPath + logo_path + picName)); group.setLogo(logo_path + picName); }}
<input id= "logoFile" style=" width: 300px; height: 35px;"data-options= "prompt:'Choose a file...',required:true" name="logo" value= "${g.logo}" ></input > $(function() { $( '#logoFile').filebox({ buttonText : 'Choose File', buttonAlign : 'right', onChange : function() { var name = $( '#logoFile').filebox( 'getValue'); var allowExtention = new Array( "jpg", "png"); var len = name.length; var math = name.substring(len - 3, len); Boolean f = false; for ( var i = 0; i < allowExtention.length; i++) { if (allowExtention[i] == math) { f = true; } } if ($.trim(name) != "" && f == false) { alert( '请选择jpg、png图片' ); $( '#logoFile').filebox( 'clear') } } }); });
以上就是相关代码,初涉EasyUI,有不对的地方请多多指教
0 0
- EasyUI 结合spring MVC上传图片以及验证图片是否符合规范
- Kissyui 结合spring mvc上传图片功能
- spring mvc 图片上传
- spring mvc 上传图片
- Spring MVC 图片上传
- Spring mvc图片上传
- spring mvc 上传图片
- spring mvc 图片上传
- spring mvc 图片上传
- spring mvc 上传图片
- Spring MVC-图片上传
- Spring MVC上传图片
- Spring MVC 图片验证码
- Spring Mvc 上传图片代码
- spring MVC 上传图片 DEMO
- spring mvc+xheditor图片上传
- 使用Spring MVC上传图片
- form图片上传+spring MVC
- 杰出程序员的十大特质
- 在需求分析中就可以避免的那些错误10
- 编译opencv程序错误调试集合
- 测试驱动开发实践 - Test-Driven Development(转)
- Android中创建Message两种方法比较,new Message和obtainMessage
- EasyUI 结合spring MVC上传图片以及验证图片是否符合规范
- 搭建简单的OSGI的hello world
- 设置虚拟linux系统的桥接网络
- eclipse插件卸载
- Point Cloud Library 1.7.2编译及使用详细教程
- 第1章 android发展史
- iOS截屏
- Android 自定义控件 轻松实现360软件详情页
- js实现获取当前时间的前几天日期