public class FileDown extends HttpServlet { public FileDown() { super(); }
public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response); }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.addHeader("Content-Disposition", "attachment;filename=" + new String("送.txt".getBytes("GBK"),"ISO8859_1")); response.setContentType("text/html"); PrintWriter out = response.getWriter(); FileInputStream in = null; File f = new File("C:\\送.txt");
try { in = new FileInputStream(f); byte b[] = new byte[1024]; while (in.read(b, 0, 1024) != -1) { out.write(new String(b, "ISO8859_1")); } in.close();
[解决办法] //web.xml <servlet> <description>This is the description of my J2EE component</description> <display-name>This is the display name of my J2EE component</display-name> <servlet-name>FileDown</servlet-name> <servlet-class>FileDown</servlet-class> </servlet>