日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > javascript >内容正文

javascript

文件上传之Springmvc方式上传代码

發(fā)布時(shí)間:2024/4/13 javascript 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 文件上传之Springmvc方式上传代码 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head><title>Title</title> </head> <body><h3>Springmvc文件上傳</h3><form action="/springmvc_day02_02_fileupload/user/fileupload2" method="post" enctype="multipart/form-data">選擇文件:<input type="file" name="upload" /><br/><input type="submit" value="上傳" /></form></body> </html> <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><!--配置文件解析器對(duì)象--><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><property name="maxUploadSize" value="10485760" /></bean></beans> package com.learn.controller;import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.multipart.MultipartFile;import javax.servlet.http.HttpServletRequest; import java.io.File; import java.util.List; import java.util.UUID;@Controller @RequestMapping("/user") public class UserController {/*** SpringMVC文件上傳* @return*/@RequestMapping("/fileupload2")public String fileuoload2(HttpServletRequest request, MultipartFile upload) throws Exception {System.out.println("springmvc文件上傳...");// 使用fileupload組件完成文件上傳// 上傳的位置 // String path = request.getSession().getServletContext().getRealPath("/uploads/");String path = "C:\\Users\\leon\\Desktop\\uploads";// 判斷,該路徑是否存在File file = new File(path);if(!file.exists()){// 創(chuàng)建該文件夾file.mkdirs();}// 說(shuō)明上傳文件項(xiàng)// 獲取上傳文件的名稱String filename = upload.getOriginalFilename();// 把文件的名稱設(shè)置唯一值,uuidString uuid = UUID.randomUUID().toString().replace("-", "");filename = uuid+"_"+filename;// 完成文件上傳upload.transferTo(new File(path,filename));return "success";} }

?

超強(qiáng)干貨來(lái)襲 云風(fēng)專訪:近40年碼齡,通宵達(dá)旦的技術(shù)人生

總結(jié)

以上是生活随笔為你收集整理的文件上传之Springmvc方式上传代码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。