编程语言   发布时间:2022-06-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了SpringMVC当中请给出一个下载的例子,文件名必需是中文大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

4.文件下载例4.1:<%@ page contentType="text/html; charset=GBK" %><html><body ><A href="http://localhost:8080/SpringMVC1/DownLoad.do?file=ibatis环境搭建.ppt">下 载ibatis环境搭建.ppt</A></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;@Controllerpublic class @R_696_11423@loWorldController 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("/DownLoad.do")    public void downloadF(httpServletrequest request, httpServletResponse response,            httpSession sesssion)  throws IOException, ServletException {         java.io.bufferedInputStream bis = null;        java.io.bufferedOutputStream bos = null;        try {            String filenameiso = request.getParameter("file");            System.out.println("filenameiso is " + filenameiso);            String filenamegbk = new String(filenameiso.getBytes("iso8859-1"), "GBK");            System.out.println("filenameutf is " + filenamegbk);            response.setContentType("application/x-msdownload");

 

更多内容请见原文,文章转载自:https://blog.csdn.net/qq_44639795/article/details/100312488

大佬总结

以上是大佬教程为你收集整理的SpringMVC当中请给出一个下载的例子,文件名必需是中文全部内容,希望文章能够帮你解决SpringMVC当中请给出一个下载的例子,文件名必需是中文所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。