前段页面:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html >
<html>
<head>
<title>个人信息</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="width=device-width; initial-scale=1.0; minimum-scale=1.0; maximum-scale=1.0;user-scalable=no" name="viewport">
<meta content="640" name="MobileOptimized">
<meta content="YES" name="apple-touch-fullscreen">
<meta content="yes" name="apple-mobile-web-app-capable">
<link href="${ROOT_PATH }content/css/staff/employee.css" type="text/css" rel="stylesheet"/>
<link href="${ROOT_PATH }content/css/staff/font-awesome.min.css" type="text/css" rel="stylesheet"/>
<script src="${ROOT_PATH }content/scripts/jquery-1.10.1.min.js"></script>
<script src="${ROOT_PATH }content/scripts/jquery.form.js"></script>
<script src="${ROOT_PATH }content/scripts/staff/staff.js"></script>
</head>
<body>
<form action="${ROOT_PATH }Staff/index/upload" name="stafform" id="stafform" method="post">
<c:set var="head" value="${ROOT_PATH }content/images/staff/photo.png"/>
<c:if test="${!empty staff.imageurl.value }">
<c:set var="head" value="${staff.imageurl.value }"/>
</c:if>
<c:set var="headx" value="${ROOT_PATH }content/images/staff/img1.jpg"/>
<c:if test="${!empty staff.imageurlb.value }">
<c:set var="headx" value="${staff.imageurlb.value }"/>
</c:if>
<div class="avatar"><a class="photo" href="#"><img id="imghead" src="${head}"/><input id="imagev" name="image" onchange="previewImage(this)" type="file" class="photo_put" value="" /></a><input type="text" name="hm" value="${staff.staffename.value}"/></div>
<div class="per_infor_box">
<ul class="per_infor">
<li><label>门 店</label><input type="text" value="${staff.commpanyName.value}" disabled="disabled" /></li>
<li><label>职 位</label><input type="text" value="${staff.position.value }" disabled="disabled"/></li>
<li><label>姓 名</label><input type="text" value="${staff.staffname.value }" disabled="disabled"/></li>
<li><label>手 机</label><input type="text" value="${staff.mobilephone.value }" disabled="disabled"/></li>
<li><label>工 龄</label><input type="text" value="${staff.workTime.value }" disabled="disabled"/></li>
<li><label>身份证</label><input type="text" value="${staff.pccid.value }" disabled="disabled"/></li>
<li><label>自我介绍</label><textarea disabled="disabled">${staff.description.value }</textarea></li>
</ul>
</div>
<div class="bottom infor_bot">
<input class="present" type="submit" value="提 交"/>
</div>
</form>
</body> <script type="text/javascript">
$(function () {
$('#stafform').submit(function () {
var options = {
dataType: 'json',
success: function (txt) {
if (txt.isok) {
alert("保存成功");
location.reload(true);
return false;
} else {
alert(txt.data);
return false;
}
}
};
$('#stafform').ajaxSubmit(options);
return false;
});
});
</script>
</html>

后台代码:

package amani.wechat.platform.controller;

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map; import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.xml.bind.JAXBElement; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile; import amani.wechat.platform.controller.model.Result;
import amani.wechat.platform.services.ICommonService;
import amani.wechat.platform.utils.CompressPic;
import amani.wechat.platform.webserviceClient.StaffHairDesignerInfo;
import amani.wechat.platform.webserviceClient.Staffinfo;
import amani.wechat.platform.webserviceClient.imageService.ImageCloudService;
import amani.wechat.platform.webserviceClient.imageService.ImageCloudServicePortType; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; @Controller
@RequestMapping("/Staff")
public class StaffController { @Resource(name="CommonService")
ICommonService commonService ; static ImageCloudServicePortType aImageCloudServicePortType; static{
ImageCloudService aImageCloudService = new ImageCloudService();
aImageCloudServicePortType = aImageCloudService.getImageCloudServiceHttpPort();
}
/**
* 更新头像和昵称
* @param image
* @param hm
* @param session
* @return
* @throws IOException
*/
@RequestMapping(value = "/index/upload", method = RequestMethod.POST)
@ResponseBody
public Result indexUpload(@RequestParam(value = "file", required = false)MultipartFile image, String hm, HttpSession session) {
String imagePath = "";
String imagebPath = "";
Result res = new Result();
String openid = session.getAttribute("openid")+"";
res.setIsok(true);
if(image!=null){
String fileName = new Date().getTime() + "_" + image.getOriginalFilename();
String key = fileName;
try {
byte[] img = CompressPic.compressPic(image.getInputStream(), 300, 300);
imagePath = aImageCloudServicePortType.uploadFile(img, "amani", key);
Gson gson = new Gson();
Map<String, String> map = gson.fromJson(imagePath, new TypeToken<Map<String, String>>(){}.getType());
imagePath = map.get("url");
} catch (Exception e) {
e.printStackTrace();
}
}
commonService.updateStaffInfo(openid, hm, imagePath, imagebPath); return res;
}
}

改成

@RequestParam(value = "file",就ok了

解决 jquery.form.js和springMVC上传 MultipartFile取不到信息的更多相关文章

  1. jquery.form.js实现异步上传

    前台页面 @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewpor ...

  2. [Asp.net mvc]jquery.form.js无刷新上传

    写在前面 最近在自己的网盘项目中想用ajax.beginform的方式做无刷新的操作,提交表单什么的都可以,但针对文件上传,就是个鸡肋.在网上查找了发现很多人都遇到了这个问题,大部分都推荐使用jque ...

  3. jquery.form.js ajax提交上传文件

    项目中最近有用到表单提交,是带有图片上传的表单录入,需要ajax异步提交,网上找了好多例子都是只能提交上传字段一个信息的,这里整理一下.表单里有普通文本信息字段也有图片上传字段. 1.jsp代码--引 ...

  4. jquery.form.js 实现异步上传

    前台: <form id="formSeacrh" action="/ResumeInfo/uploadFile" method="post&q ...

  5. jquery.form 兼容IE89文件上传

    导入部分 <script type="text/javascript" src="js/jquery-1.8.3.min.js" charset=&quo ...

  6. asp.net使用jquery.form实现图片异步上传

    首先我们需要做准备工作: jquery下载:http://files.cnblogs.com/tianguook/jquery1.8.rar jquery.form.js下载:http://files ...

  7. jQuery.form Ajax无刷新上传错误 (jQuery.handleError is not a function) 解决方案

    今天,随着ajaxfileupload时间firebug财报显示,"jQuery.handleError is not a function"错误.因为一旦使用jQuery.for ...

  8. 文件上传---form表单,ajax,jquery,以及iframe无刷新上传 (processData,contentType讲解)

    服务端程序: import tornado.web import os IMG_LIST=[] class IndexHandler(tornado.web.RequestHandler): def ...

  9. jQuery File Upload跨域上传

    最近在做一个一手粮互联网项目,方案为前后端分离,自己负责前端框架,采用了Requirejs+avalonjs+jquery三个框架完成. 前后端通过跨域实现接口调用,中间也发现了不少问题,尤其是在富文 ...

随机推荐

  1. 使用Chrome快速实现数据的抓取(四)——优点

    些一个抓取WEB页面的数据程序比较简单,大多数语言都有相应的HTTP库,一个简单的请求响应即可,程序发送Http请求给Web服务器,服务器返回HTML文件.交互方式如下: 在使用DevProtocol ...

  2. Effective JavaScript Item 35 使用闭包来保存私有数据

    本系列作为EffectiveJavaScript的读书笔记. JavaScript的对象系统从其语法上而言并不鼓舞使用信息隐藏(Information Hiding).由于当使用诸如this.name ...

  3. 为什么说CLR是类型安全的

    CLR总是知道托管堆上的对象是什么类型,这是CLR类型安全的前提.托管堆上的每个对象都有一个"类型对象指针",指向托管堆上Type对象的一个实例.我们总是可以通过System.Ob ...

  4. 别忽视UIImage中的方向属性, imageOrientation-转

    转 : 别忽视UIImage中的方向属性, imageOrientation

  5. C# 结构体定义 转换字节数组 z

    客户端采用C++开发,服务端采用C#开发,所以双方必须保证各自定义结构体成员类型和长度一致才能保证报文解析的正确性. [StructLayoutAttribute(LayoutKind.Sequent ...

  6. Android定制争夺战 三大主流ROM横评

    随着MIUI在广大“机油”们心目中位置的逐渐攀升,越来越多的厂商也相继推出了属于自己的定制Android ROM,想以此来抢占这一新兴市场,像点心OS.腾讯的Tita以及近期比较热门的百度云ROM等等 ...

  7. 基于非比較的排序:计数排序(countSort),桶排序(bucketSort),基数排序(radixSort)

    计数排序 条件:要排序的数组的元素必须是在一定范围的,比方是1~100.在排序之前我们必须知道数组元素的范围. 思路:顾名思义:就是用一个数组来计数的. 步骤: 1.用一个数组来计数count[ ], ...

  8. iptables只允许指定ip地址访问指定端口

    首先,清除所有预设置 iptables -F#清除预设表filter中的所有规则链的规则 iptables -X#清除预设表filter中使用者自定链中的规则 其次,设置只允许指定ip地址访问指定端口 ...

  9. android之使用mvn构建创造项目步骤

    转自:http://blog.csdn.net/luhuajcdd/article/details/8132386 手动的创建自己的android application   1.用android t ...

  10. Eclipse中运行Tomcat遇到的内存溢出错误

    使用Eclipse(版本Indigo 3.7)调试Java项目的时候,遇到了下面的错误: Exception in thread "main" Java.lang.OutOfMem ...