Displaying pdf in jsp

后端 未结 3 1792
既然无缘
既然无缘 2020-11-27 08:15

I have written a jsp page to display contents of pdf, but end up with ascii codes in jsp. I want to display the contents of pdf in jsp. Whats the part that I have missed. Wh

3条回答
  •  旧巷少年郎
    2020-11-27 08:47

    I could see multiple problems:

    • There are extra html tags at the top and bottom of your JSP. You do not want them there - you only want to have the pdf contents in your response output.
    • The code sets content type is multiple times. That is probably not the root cause, however make sure you do it only once (set it to application/pdf)
    • In the while loop, data are first written to the response output stream, then a toString() is written to the out (which is actually a Writer instance opened on the response output stream - the one in outs). Only use the response stream in the loop, as

      while ((c = in.read(buf, 0, buf.length)) > 0) { outs.write(buf, 0, c);
      }

提交回复
热议问题