使用jspsmartuploader下载出现问题
package myjob.web;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.jspsmart.upload.*;
public class doDownload extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK ";
private ServletConfig config;
//Initialize global variables
public void init() throws ServletException {
this.config = config;
}
final public ServletConfig getServletConfig(){
return config;
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
String downfile = null;
try{
downfile = "d:\\tmp\\a.txt ";
if (downfile!=null)
downloadfile(request, response, downfile);
}catch(Exception e){
PrintWriter out = response.getWriter();
out.print( "downfile error. ");
String err=e.getMessage();
out.print(err);
}
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
private void downloadfile(HttpServletRequest request, HttpServletResponse response, String filename) throws Exception{
// 新建一个SmartUpload对象
SmartUpload mySmartUpload = new SmartUpload();
mySmartUpload.initialize(config, request, response); mySmartUpload.setContentDisposition( "inline; ");
mySmartUpload.downloadFile(filename,null, "a.txt ");
}
}
源代码如上,使用时是在jsp文件中 <a href= "doDownload " title= "点击这里下载文件 "> 下载 </a> ,点击下载。
运行后显示null,经检查,发现config为null,导致调用downloadfile时出现异常,显示错误为null。还应该做其他的设置么?
[解决办法]
如果是ServletConfig 为空,那与Smartupload没关
[解决办法]
jf
[解决办法]
我也遇到相同问题,请楼主告诉我
[解决办法]
CSDN的分有毛用,弱弱的问?