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;

@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("/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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mark_to_win

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值