package com.file.downloading;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.jspsmart.upload.SmartUpload;
public class DownloadFile extends HttpServlet {
private ServletConfig config;
public final void init(ServletConfig config) {
this.config = config;
}
protected void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
SmartUpload su = new SmartUpload();
System.out.println("this.config is null : "
+ (null == this.config));
su.initialize(this.config, request, response);
su.setContentDisposition(null);
su.downloadFile("newfile.txt");
} catch (Exception ex) {
System.out.println(this.getClass().getName() + " error "
+ ex.toString());
} finally {
out.close();
}
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}
}
这段代码可以执行,文件也可以下载,但是下载后的文件内容为空,请教?!
这段代码可以执行,文件也可以下载,但是下载后的文件内容为空,请教?!
这段代码可以执行,文件也可以下载,但是下载后的文件内容为空,请教?!
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.jspsmart.upload.SmartUpload;
public class DownloadFile extends HttpServlet {
private ServletConfig config;
public final void init(ServletConfig config) {
this.config = config;
}
protected void processRequest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
SmartUpload su = new SmartUpload();
System.out.println("this.config is null : "
+ (null == this.config));
su.initialize(this.config, request, response);
su.setContentDisposition(null);
su.downloadFile("newfile.txt");
} catch (Exception ex) {
System.out.println(this.getClass().getName() + " error "
+ ex.toString());
} finally {
out.close();
}
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}
}
这段代码可以执行,文件也可以下载,但是下载后的文件内容为空,请教?!
这段代码可以执行,文件也可以下载,但是下载后的文件内容为空,请教?!
这段代码可以执行,文件也可以下载,但是下载后的文件内容为空,请教?!