标签:gbk isp text inpu ring ram etc tps end
1 <body> 2 <a href="/day10/down?name=day10笔记.txt">day10笔记.txt</a> 3 </body>
public class DownServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String name = req.getParameter("name"); String n=new String(name.getBytes("iso8859-1"),"utf-8"); ServletContext context = this.getServletContext(); String mimeType = context.getMimeType(n); resp.setContentType(mimeType); resp.setHeader("content-disposition", "attachment;filename="+new String(n.getBytes("gbk"),"iso8859-1")); InputStream in = context.getResourceAsStream("/"+n); ServletOutputStream os = resp.getOutputStream(); IOUtils.copy(in, os); in.close(); os.close(); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req, resp); } }
标签:gbk isp text inpu ring ram etc tps end
原文地址:http://www.cnblogs.com/may12138/p/7259028.html