file表单提交的Ajax,ajax提交包含file的表单

本项目基于spring mvc框架,是一个maven项目;

主要是利用FormData来提交表单;

首先在pom.xml加入依赖:

项目代码:http://download.csdn.net/detail/liujan511536/9489630

org.springframework

spring-webmvc

4.2.1.RELEASE

commons-fileupload

commons-fileupload

1.3

org.apache.commons

commons-lang3

3.3.2

servlet-api

servlet-api

2.5

然后在applicaitonContext.xml中加入:

前端jsp代码:

Title

file:

name:

upload

后台controlelr代码:

package com.liujan.controller;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.ResponseBody;

import org.springframework.web.multipart.MultipartFile;

import org.springframework.web.multipart.MultipartRequest;

import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

import java.io.File;

/**

* Created by liujan on 4/12/16.

*/

@Controller

public class HelloController {

@RequestMapping(value = "/")

public String show() {

return "upload";

}

@RequestMapping(value = "uploadfile.html " )

@ResponseBody

public String upload(HttpServletRequest request, @RequestParam("file") MultipartFile file,

@RequestParam("name") String name) {

if (name != null) {

String fileName = file.getOriginalFilename();

System.out.println("name:" + name + " file:" + fileName);

}

return "good";

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值