前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >请给出一个SpringMVC文件上传的SmartUpload版例子

请给出一个SpringMVC文件上传的SmartUpload版例子

作者头像
马克java社区
修改2019-09-29 17:43:12
5440
修改2019-09-29 17:43:12
举报
文章被收录于专栏:java大数据

3.文件上传 例3.1: <%@ page contentType="text/html; charset=GBK" %> <html> <body> <h1> <% if(request.getParameter("i")!=null) { out.print("上传了"+request.getParameter("i")+"个文件"); } %> </h1> we must use post, otheriwse, report negativeArray error. <form method="post" action="uploadF.do" enctype="multipart/form-data"> <br> <input type="text" name="user" value="可以中文"/> <!--the following name does not matter.--> <input type="file" name="upload"/> <input type="file" name="upload1"/> <br> <input type="submit" name="Submit" value="Submit"> <input type="reset" value="Reset"> </form> </body> </html> package com; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.context.ServletConfigAware; import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.support.WebApplicationContextUtils; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.support.RequestContextUtils; import com.jspsmart.upload.File; import com.jspsmart.upload.Files; import com.jspsmart.upload.SmartUpload; import com.jspsmart.upload.SmartUploadException; @Controller public class HelloWorldController implements ServletConfigAware,ServletContextAware { private ServletContext servletContext; @Override public void setServletContext(ServletContext arg0) { this.servletContext = arg0; } private ServletConfig servletConfig; @Override public void setServletConfig(ServletConfig arg0) { this.servletConfig = arg0; } @RequestMapping("/uploadF.do") public void uploadF(HttpServletRequest request, HttpServletResponse response, HttpSession sesssion) throws IOException, ServletException { System.out.println("user1 is " + request.getParameter("user")); SmartUpload su = new SmartUpload(); int i = 0; ServletContext sec=RequestContextUtils.getWebApplicationContext(request).getServletContext(); ApplicationContext app = WebApplicationContextUtils.getWebApplicationContext(sec); String s = sec.getRealPath(""); System.out.println("s is" + s); su.initialize(servletConfig, request, response); try { su.upload();

更多请见:https://blog.csdn.net/qq_44639795/article/details/100191587

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档