一、界面效果

二、html代码

 <legend>上传APK文件</legend>
<form action="<%=basePath%>/apks/commitApk" class="form-horizontal" method="post" enctype="multipart/form-data">
<input name="cityCode" value="${s0.paramValue}" type="hidden"/>
<input name="productCode" value="${s.paramValue}" type="hidden"/>
<div class="form-group">
<label for="ticket-message" class="col-sm-3 control-label col-md-1">版本号</label>
<div class="col-md-4">
<input type="text" class="form-control" name="versionCode" id="versionCode" placeholder="请输入整数">
</div>
</div>
<div class="form-group">
<label for="ticket-message" class="col-sm-3 control-label col-md-1">版本名</label>
<div class="col-md-4">
<input type="text" class="form-control" name="versionName" id="versionName" placeholder="0.0.0.1">
</div>
</div>
<div class="form-group">
<label for="ticket-message" class="col-sm-3 control-label col-md-1">描述</label>
<div class="col-md-4">
<textarea class="form-control" name="versionDesc" id="versionDesc" rows="5" cols="30" placeholder="版本描述"></textarea>
</div>
</div>
<div class="form-group">
<label for="ticket-message" class="col-sm-3 control-label col-md-1">文件</label>
<!-- <label for="ticket-attachment" class="col-sm-3 control-label">请选中apk文件</label> -->
<div class="col-md-4">
<input type="file" name="apkFile" id="apkFile">
<p class="help-block"><em>文件类型: .apk</em></p>
</div>
</div>
<div class="form-group">
<label for="ticket-message" class="col-sm-3 control-label col-md-1"></label>
<div class="col-md-4">
<input id="apkSubmitBtn" type="submit" class="btn btn-danger"></input>
</div>
</div>
</form>

三、后台java代码

 @RequestMapping(value = "/commitApk", method = RequestMethod.POST)
public @ResponseBody ModelAndView commitApk(@RequestParam("cityCode") String cityCode,@RequestParam("productCode") String productCode,
@RequestParam("apkFile") CommonsMultipartFile[] apkFile,@RequestParam("versionCode") int versionCode,@RequestParam("versionName") String versionName,
@RequestParam("versionDesc") String versionDesc, HttpSession session) {
FileOutputStream out = null;
FileInputStream in = null;
try {
String appPath = System.getProperty("root");
appPath = appPath.substring(0, appPath.indexOf("ExceptionManageSystem"));
StringBuffer buffer = new StringBuffer(appPath + com.tongyan.ems.common.Constants.APKMANAGER_FILES_PAHT);
buffer.append(productCode).append("\\").append(cityCode).append("\\");
File fileDir = new File(buffer.toString());
if(!fileDir.exists()) {
fileDir.mkdirs();
}
buffer.append(apkFile[0].getFileItem().getName());
File file = new File(buffer.toString());
if(!file.exists()) {
file.createNewFile();
} else {
file.delete();//如果存在就删除重新上传
}
out = new FileOutputStream(file); in = (FileInputStream)apkFile[0].getInputStream();
int read = 0;
byte[] b = new byte[1024];
while((read = in.read(b)) != -1) {
out.write(b, 0, read);
}
//数据入库
ApkManagerPo apkManagerPo = new ApkManagerPo();
apkManagerPo.setApkCode(UUID.randomUUID().toString());
apkManagerPo.setCreateDate(new SimpleDateFormat(Constants.DATE_FORMAT).format(new Date()));
apkManagerPo.setProductCode(productCode);
apkManagerPo.setCustomerCode(cityCode);
apkManagerPo.setVersionCode(versionCode);
apkManagerPo.setVersionName(versionName);
apkManagerPo.setVersionDesc(versionDesc);
if(session.getAttribute("User") != null) {
UserPo user = (UserPo)session.getAttribute("User");
apkManagerPo.setUserId(user.getUserId());
}else {
apkManagerPo.setUserId("");
}
apkManagerPo.setApkRoute(com.tongyan.ems.common.Constants.FEEDBACK_FILES_PAHT + productCode + "\\" + cityCode + "\\" + apkFile[0].getFileItem().getName());//文件夹放在webApp下面
apkManagerPo.setApkPath(com.tongyan.ems.common.Constants.FEEDBACK_FILES_URL + productCode + "/" + cityCode + "/" + apkFile[0].getFileItem().getName());
apkService.addApkVersion(apkManagerPo);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(out != null) {
out.close();
}
if(in != null) {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}

此代码为form表单提交,现改需要改为js提交,故做记录

一个用于ajax上传的js插件

http://files.cnblogs.com/files/royi123/ajaxfileupload_JS_File.rar

一篇关于SpringMVC 传统文件上传的方法的更多相关文章

  1. TZ_06_SpringMVC_传统文件上传和SpringMVC文件上传方式

    1.传统文件上传方式 <!-- 文件上传需要的jar --> <dependency> <groupId>commons-fileupload</groupI ...

  2. 关于SpringMVC的文件上传

    关于文件的上传,之前写过2篇文章,基于Struts2框架,下面给出文章链接: <关于Struts2的文件上传>:http://www.cnblogs.com/lichenwei/p/392 ...

  3. 6.学习springmvc的文件上传

    一.文件上传前提与原理分析 1.文件上传必要前提: 2.文件上传原理分析: 3.需要引入的jar包: 二.传统方式文件上传程序 1.pom.xml <dependency> <gro ...

  4. 使用springmvc实现文件上传

    该配置在javaweb上传文件篇中的基础上进行配置:https://www.cnblogs.com/flypig666/p/11745182.html 1.配置文件解析器,在springmvc.xml ...

  5. 【SpringMVC】SpringMVC 实现文件上传

    SpringMVC 实现文件上传 文章源码 文件上传回顾 查看 JavaWeb 阶段的文件上传下载 实现步骤: 客户端: 发送 post 请求,告诉服务器要上传什么文件 服务器: 要有一个 form ...

  6. springmvc图片文件上传接口

    springmvc图片文件上传 用MultipartFile文件方式传输 Controller package com.controller; import java.awt.image.Buffer ...

  7. SpringMVC学习--文件上传

    简介 文件上传是web开发中常见的需求之一,springMVC将文件上传进行了集成,可以方便快捷的进行开发. springmvc中对多部件类型解析 在 页面form中提交enctype="m ...

  8. Spring +SpringMVC 实现文件上传功能。。。

    要实现Spring +SpringMVC  实现文件上传功能. 第一步:下载 第二步: 新建一个web项目导入Spring 和SpringMVC的jar包(在MyEclipse里有自动生成spring ...

  9. SpringMVC单文件上传、多文件上传、文件列表显示、文件下载(转)

    林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 本文详细讲解了SpringMVC实例单文件上传.多文件上传.文件列表显示.文件下载. 本文工程 ...

随机推荐

  1. uva 1001(最短路)

    题意:在一个三维的奶酪里面有n(n<=100)个洞,老鼠A想到达老鼠B的位置,在洞里面可以瞬间移动,在洞外面的移动速度为10秒一个单位,求最短时间 题解:如果两个洞相交,那么d[i][j]=0: ...

  2. iScroll4.2.5中的无法滑动或点击的解决方案(转)

    又见iScroll问题,特别是三星手机和iPhone,顺便提一句,现在的项目中他们给div加了height属性来解决不能滚动问题,个人认为是个非常愚蠢的解决方案,我必须使用media query来解决 ...

  3. 各种边缘检测算子特点比较(canny)

    canny 最好.但是容易把噪点误判为边界.sobel prewitt log 效果差不多.prewitt比sobel 去噪效果好.roberts马马虎虎.适合什么图片那得看图片的噪点情况,一般can ...

  4. JavaScript对象中的属性(可写,可配置,可枚举,value,getter,setter)

    JavaScript中,对象包括3个特性,分别为,可扩展性,class标识符,属性. 如果对象的可扩展性为false,则不可为对象动态的添加属性.   对象包含分为存取器属性和值属性.存取属性为 {g ...

  5. The data is said to include information from networks

    The data is said to include information from networks as well as from individual computers and smart ...

  6. libdispatch for Linux

    这个Dispatch是苹果的一个高效的处理库,它在ubuntu上的安装如下: Build/Runtime Requirements 如下: libBlocksRuntime libpthread_wo ...

  7. SharePoint\O365 CSOM操作"请求访问设置"功能

    博客地址:http://blog.csdn.net/FoxDave 请求访问设置是在SharePoint网站权限菜单中的一个功能,如下图: 它用来设置成员是否可以共享网站以及个别文件和文件夹,是否允许 ...

  8. realestate.cei.gov.cn

    using AnfleCrawler.Common; using System; using System.Collections.Concurrent; using System.Collectio ...

  9. 5、Linux下面桌面的安装

    搭建本地yum仓库的方法 http://www.cnblogs.com/lql123/p/5952788.html 1.yum grouplist        (列出yum仓库里的软件组列表) .y ...

  10. JavaScript基础--简单功能的计算器(十一)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...