一個難題,servlet高手請進!
我在做一個jsp頁面的時候,點擊鏈接打開文檔,用了一個servlet處理,
比如 The test fiel( /Openfile?filename=data/test.xls)
-----------------------------------------------
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException,
IOException {
HttpSession session = request.getSession();
String filename = request.getParameter( "file_name ");
filename = Globals.RTC_UP_PATH + "/ " + filename;
response.setHeader( "Content-disposition ",
"attachment;filename= " +
filename.replace( '\\ ', '/ ').
substring(filename.lastIndexOf( "/ ")));
String ext=filename.substring(filename.lastIndexOf( ". ")+1);
if(ext.equalsIgnoreCase( "xls ")){
System.out.println( "xlsfile: "+filename);
response.setContentType( "application/vnd.ms-excel ");
}
else{
System.out.println( "html: "+filename);
response.setContentType( "text/html ");
}
File doc = new File(filename);
ServletOutputStream out = response.getOutputStream();
FileInputStream fin = new FileInputStream(doc);
int b;
while ( (b = fin.read()) != -1) {
out.write(b);