?? configparamservlet.java
字號:
/*
* Created on 2004-6-13
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package com.servlet;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author haoyulong
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class ConfigParamServlet extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse res) throws ServletException, IOException {
//TODO Method stub generated by Lomboz
res.setContentType( "application/pdf" );
ServletOutputStream out =res.getOutputStream ();
File pdf =null;
BufferedInputStream buf=null;
//獲取初始化參數
String pdfDir = getServletConfig( ).getInitParameter("FilePath");
if (pdfDir == null || pdfDir.equals(""))
throw new ServletException(
"Servlet parameters Wrongs");
try{
pdf=new File(pdfDir+"sample.pdf");
res.setContentLength( (int) pdf.length( ) );
FileInputStream input = new FileInputStream(pdf);
buf = new BufferedInputStream(input);
int readBytes = 0;
//read from the file; write to the ServletOutputStream
while((readBytes = buf.read( )) != -1)
out.write(readBytes);
}
catch(IOException e){
System.out.println("file not found!");
}finally {
//close the input/output streams
if (out != null)
out.close( );
if (buf != null)
buf.close( );
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -