关于读PDF的问题~~~急在线等
小生我写了一个用servlet显示FTP上的文档的程序,现在有些问题,就是在调用该servlet的时候出现的不是显示,是下载
请问各位大虾改怎么办啊~~~救命啊在~~~~
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String type=request.getParameter("type");
String fileName=request.getParameter("fileName");
if(type.equals("doc") ¦ ¦type.equals("DOC")){
content_type="application/vnd.ms-word";
type="doc";
}
else if(type.equals("pdf") ¦ ¦type.equals("PDF")){
content_type="application/pdf";
type="pdf";
}
String file=fileName+"."+type;
response.setContentType(content_type);
ServletOutputStream out=response.getOutputStream();
FtpClient ftp=new FtpClient(FTP_NAME);
ftp.login("username","password");
ftp.cd("pdf");
try{
ftp.binary();
TelnetInputStream in=ftp.get(fileName+"."+type);
byte[] b=new byte[1024];
int len=0;
while((len = in.read(b)) != -1){
out.write(b,0,len);
out.flush();
}
out.close();
if(in!=null){
in.close();}
}catch(Exception e){
System.err.println(e);
}