Announcement Announcement Module
Collapse
No announcement yet.
How to display PDF file in JSP with byte array (but without using file system) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to display PDF file in JSP with byte array (but without using file system)

    Hi, I use spring framework develop web application. In my application, controller get the user uploaded file as byte array value, and store this byte array value in MySQL DB in the column of BLOB type(Without using file system on server). Now, I retrieve the byte array value from DB and transfer this byte array to JSP layer, what I want is the pdf file can be shown on that JSP page.

    What I have done is using another controller to get the report id according to user mouse selection, and retrieve the file object from DB according to id, get the file byte array value . Then ,I try to use the following method to tell JSP what is the type of the file to be shown.

    myController.java:
    Code:
    public class myController extends SimpleFormController{
    ...
    protected ModelAndView onSubmit(......){
    .....
    response.setContentType("application/pdf");
     response.setContentLength(byteArray.length); 
    .......
    }
    ...
    }
    What is the next step? how to transfer the byte array value to JSP?How to convert the byte array to pdf which will be shown on this JSP page(* I do not use file system in this application, so, no file create on server).
    Last edited by blust1984; Jul 19th, 2007, 09:58 AM.

  • #2
    I would say that the next step is to
    * simply response.write(byteArray) (or whatever it is called) and
    * return null ModelAndView to express the fact that the request processing is over.

    Comment


    • #3
      creating Excel file

      Hi In Spring
      org.springframework.web.servlet.view.document.Abst ractPdfView class provides the support for generating the pdf file.

      you have to override the buildPdfDocument(..) method.

      Comment


      • #4
        now,How to render PDF file to be shown with byte array?

        Originally posted by prakash_cse_2003 View Post
        Hi In Spring
        org.springframework.web.servlet.view.document.Abst ractPdfView class provides the support for generating the pdf file.

        you have to override the buildPdfDocument(..) method.
        I think, my case is not suitable to use Spring AbstractPdfView, since my application is to upload the exist PDF file to server and render it on JSP page without using any file system. AbstractPdfView is to organize a new PDF file.

        Original posted by macar

        I would say that the next step is to
        * simply response.write(byteArray) (or whatever it is called) and
        * return null ModelAndView to express the fact that the request processing is over.
        Hi,I use the following way to transfer the byte array to JSP layer:
        Code:
        byte[] file=fileFromDB.getFile();
        response.setContentType("application/pdf");
        response.setContentLength(file.length);				
        response.getOutputStream().write(file, 0, file.length);
        The problem is, though I have transfer the byte array to JSP layer with outputStream, how can JSP layer render this pdf file to be shown??

        Comment

        Working...
        X