一、界面效果

二、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. mysql索引的使用[下]

    接着上篇,我们继续来探究索引.这次我们主要来探究关于联合索引的使用和联合.多表查询的规范. 继续看一下数据: mysql> select * from student order by ID d ...

  2. js获取手机联网状态

    window.addEventListener("offline", function() { alert('offline') }, false); window.addEven ...

  3. linux 查看剩余内存数

    返回的是kb的数值 cat /proc/meminfo | grep MemFree | cut -d ":" -f2 | sed -e 's/\(^ *\)//' -e 's/\ ...

  4. JAVA 十六进制与字符串的转换

    public static String toHexString(int i)以十六进制的无符号整数形式返回一个整数参数的字符串表示形式.如果参数为负,那么无符号整数值为参数加上 232:否则等于该参 ...

  5. LeetCode 175 Combine Two Tables mysql,left join 难度:0

    https://leetcode.com/problems/combine-two-tables/ Combine Two Tables Table: Person +-------------+-- ...

  6. JavaScript Array对象 知识点总结

    1 isArray方法 该方法是Array对象的静态方法,用来判断一个值是否为数组,它可以弥补typeof运算符的不足. 用法是Array.isArray(array实例) 通用的判断对象数据类型的方 ...

  7. eclipse快捷键用不了

    ctrl+shift+R是eclipse最常用的快捷键之一,用于打开资源,输入文件名或文件名中的前几个字母,就可以打开工作区中任意文件 今天在打开eclipse,使用该快捷键时,提示“该快捷方式所指向 ...

  8. jQuery 菜单项切换

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. oracle查看当前用户权限

    查看用户和默认表空间的关系select username,default_tablespace from dba_users;--查看当前用户能访问的表select * from user_table ...

  10. CSS简单布局总结

    display  block       块级元素,占据一行 none       隐藏 inline      允许同一行显示,但不再有宽和高 inline-block   允许在一行的块级元素,可 ...