participate


Java Errors and Error Handling - Output problem when filename has Period( . ) within it in Servlet
This question is not answered.

<<   Back to Forum  |   Give us Feedback
This topic has no replies.
kamikaze426
Posts:4
Registered: 2/21/07
Output problem when filename has Period( . ) within it in Servlet   
Nov 22, 2007 9:56 PM
 
 
I have this code below that outputs the pdf file from a JSP using a servlet. The problem is if filename has period (.) (Ex. AAA.BBB.CCC.PDF) within it I gey a socket write error, and cant output the pdf file. Can anyone help me with this.

Thank You

JSP Code:
document.write("<object classid=\"clsid:CA8A9780-280D-11CF-A24D-444553540000\" id=\"BravaDTXView1\" width=\"100%\" height=\"100%\"> ");
document.write(" <param name=\"src\" value=\"/TifPdfDisplay?filepath=<%=sFilepath>\"> ");
document.write("</object>");

Servlet Code:
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding(Constants.GlobalVariable.CHARSET);

String sFilePath= (String) request.getParameter("filepath");

// Read in PDF test file
File l_file = new File(sFilePath);
FileInputStream in = new FileInputStream(l_file);
int length = in.available();
byte[] pdfbytes = new byte[length];
in.read(pdfbytes);
in.close();

// Send response
response.setContentType("application/pdf");
response.setContentLength(pdfbytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(pdfbytes, 0, pdfbytes.length);
ouputStream.flush();
ouputStream.close();

}
 
This topic has no replies.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 25
  • Guests : 132

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums