Sandesh Shashidhar

Greenhorn
+ Follow
since Feb 01, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sandesh Shashidhar

Since i need the pdf to display a popup asking do you want to open or save i am not linking it directly.
Yes my file is inside the webapp itself

Do i need to use getservletcontext.getrealpath()

If i am wrong can you please guide me
12 years ago
I need help regarding the below procedure

I have a PDF file in my Webcontent/dir/helpdir.pdf and in JSP page i am trying to download the PDF by calling a servlet
The PDF is located in Webcontent/dir folder . But when i run the program i am getting filenot found. Please guide me . Below is the code snipet

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
if (_logDebug) {
_log.debug(ENTERING + _className + ".doGet()");
}
OutputStream outStream = response.getOutputStream();
String fileName="helpDoc.pdf";
if (_logDebug) {
_log.debug("fileName"+fileName);
}
String filePath =request.getContextPath()+"//doc//";
_log.debug("File"+filePath);
File f=new File(filePath, fileName);
response.setContentType( "application/pdf" );
response.setContentLength((int)f.length());
response.setHeader("Content-Disposition","attachment; filename=\"helpDocument.pdf\"");
response.setHeader("Cache-Control", "max-age=60");
byte[] buf = new byte[50000];
FileInputStream inStream = new FileInputStream(f);
int sizeRead = 0;
while ((sizeRead = inStream.read(buf, 0, buf.length)) > 0) {
outStream.write(buf, 0, sizeRead);
}
inStream.close();
outStream.close();
}
12 years ago