I saw a post today and asked questions about application/pdf. I tried it by myself.
The details are given belowCode
Add mime information to the Web. xml of the project (you can manually change it to another format, such as word)
<Mime-mapping> <extension> pdf </extension> <mime-type> application/pdf </mime-type> </mime-mapping>
Read the PDF file in the servlet and output it to the browser for display. However, this method should be very memory-consuming. If all the large files have been read for display
Public void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {response. setcontenttype ("application/pdf; charset = UTF-8"); outputstream out = response. getoutputstream (); // response output stream fileinputstream inputstream = new fileinputstream ("D:/a.pdf"); // File Read stream filechannel channel = inputstream. getchannel (); // file channel writablebytechannel channel_out = channels. newchannel (out); // response output channel. transferto (0, channel. size (), channel_out); // transfers the file channel to the response channel for output out. flush (); out. close ();}
Last display