Hi,
I am having a weird problem.
I am calculating a file path based on User id. Later on I pass that file path to a servlet as request parameter. So that servlet can read that file and show the PDF content in new window.
Each user id has some PDF file stored in some specific location. For example, for user id "1210", file path will be "C:\audit\abc\data\34\1234.PDF".
Everytime, my servlet is invoked, the file name it print is : "C:da2volymbdata". and then it throw exception that it cant find the file specified. Why does it discard the file separator and why does it print the full path that include the file name?
I printed the file path in the browser itself for debugging purpose. I printed the correct file path. But when it is submitted to servlet, servelt discard all teh file separator. And I cant figure out why. Any help will be appreciate. Please help me debug my problem. I am runiing it in windows with local jboss server.
This is how I am calling the servlet in the jsp:
<bean:define id="path" name="ch" property="pdfPath"/>
<%
String url= "SendPDFServlet?file=" + path ;
%>
<td align="left" nowrap>
<a href="#" onClick="javascript:window.open('<%=url%>', 'PDF', 'height=600, width=800, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no');">
<bean:write name="ch" property="fullName" ignore="true"/>
</a>
</td>
This is the potion of servlet code:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// get the 'file' parameter
String fileName = (String) request.getParameter("file");
if (fileName == null || fileName.equals(""))
throw new ServletException(
"Invalid or non-existent file parameter in SendPdf servlet.");
System.out.println("*** SendPDFServlet==filename:" + fileName);
ServletOutputStream stream = null;
BufferedInputStream buf = null;
try {
stream = response.getOutputStream();
File pdf = new File(fileName);
response.setContentType("application/pdf");
response.setContentLength((int) pdf.length());
FileInputStream input = new FileInputStream(pdf);
buf = new BufferedInputStream(input);
int readBytes = 0;
while ((readBytes = buf.read()) != -1)
stream.write(readBytes);
} catch (IOException ioe) {
throw new ServletException(ioe.getMessage());
} finally {
if (stream != null)
stream.flush();
stream.close();
if (buf != null)
buf.close();
}
}