<?xml version="1.0" encoding="UTF-8" ?> <%@ page contentType="text/html; charset=UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/Dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>上传照片</title> <base href="/" target="_self" /> <jsp:directive.include file="/views/common/common_import.jsp" /> <script type="text/javascript"> $(document).ready(function() { $("input[type='file']").change(function(evt) { var files = evt.target.files; for ( var i = 0, f; f = files[i]; i++) { if (!f.type.match('image.*')) { continue; } var reader = new FileReader(); reader.onload = (function(theFile) { return function(e) { $("#list img").attr("src", e.target.result); //预览图片的位置 }; })(f); reader.readAsDataURL(f); } }); //提交表单 $("#uploadForm").ajaxForm(function() { window.close(); }); }); </script> </head> <body> <table style="width: 100%;"> <tr> <td align="center"><br /> <div class="ModelTitleCss">上传照片</div></td> </tr> </table> <br /> <form id="uploadForm" enctype="multipart/form-data" action="<%=request.getContextPath()%>/pilot/upPhoto.jspx" method="post"> <span style="padding-left: 15px; color: blue;">请从电脑上选择一张照片</span> <input type="hidden" id="pilotId" name="pilotId" /> <input type="file" id="photo" name="photo" /> <p></p> <div id="list" align="center"> <img width="125" height="150" /> </div> <p></p> <div align="center"> <input type="submit" id="btm" value="上 传" class="ButCss" /> </div> </form> </body> </html>
SpringMVC配置
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="100000" /> </bean>
Actoin
@ResponseBody @RequestMapping("/upPhoto") public void upPhoto(MultipartHttpServletRequest request, String pilotId) throws IOException { // 获得第1张图片(根据前台的name名称得到上传的文件) MultipartFile file = request.getFile("photo"); // 获得文件名: String filename = file.getOriginalFilename(); String imgtype = filename.substring(filename.lastIndexOf(".")); // 获取路径 String ctxPath = EnvironmentVariables.getValue(Constants.PHOTOS_PATH); // 创建文件 File dirPath = new File(ctxPath); if (!dirPath.exists()) { dirPath.mkdir(); } String pathname = ctxPath + pilotId + imgtype;// 存放路径 File uploadFile = new File(pathname); FileCopyUtils.copy(file.getBytes(), uploadFile); ); }
相关推荐
springMVC上传图片附件示例项目,多个图片上传,带选择图片后回显,带普通text类型文本域传值。有需要的尽管拿走。
SpringMVC文件上传Demo代码
springmvc上传文件controller,vue
SpringMvc上传本地图片保存数据库并实时显示
使用springmvc实现图片上传,希望大家多多支持了,多多评论。
该demo基于springmvc,监听spring的processerListener接口,实现对上传数据的更新,同时采用进度条显示当前上传情况。
本资源是基于Springmvc的图片上传案例,并对上传的图片添加了生成缩略图的功能。
springMVC上传图片附件示例项目,多个图片上传,带选择图片后回显,带普通text类型文本域传值。有需要的尽管拿走。
用spring,springmvc,mybatis实现图片的上传和回显,图片地址在tomcat里面设置
主要为大家详细介绍了springMVC图片上传的处理方式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
主要介绍了springmvc图片上传及json数据转换过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
单图片上传到本地,编辑框回显, 多图片上传 回显。springmvc整合完成项目 详情 https://blog.csdn.net/m0_37946870/article/details/79913803
http://blog.csdn.net/madcode2222222222222/article/details/78326347
基于SSM(Spring+SpringMvc+Mybatis)框架的图片上传并保存到数据库中与回显的案例
springmvc上传文件所需jar包springmvc上传文件所需jar包 springmvc上传文件所需jar包
主要为大家详细介绍了SpringMVC框架实现图片上传与下载,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
SpringMVC上传图片文件到 阿里云,亲测可用。前端使用Ajax。
就是简单的一个springmvc上传文件的示例。上传图片后可以显示图片,适合新手学习
bootstrap+springMvc+spring图片上传下载,生成固定格式的json文件,以及将上传图片和json文件进行压缩打包操作
java 基于springMVC多图片上传,MySQL源码 @Controller @RequestMapping("/upload") public class UploadFileController { @Autowired private UploadFileService uploadFileService; @RequestMapping("/...