• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Caching rendered html in jsp

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

My requirement is to capture the html that has been rendered in jsp and convert into PDF.
I wanted help as to how to access the rendered html from the jsp.

Also, in case there is an alternate way, I would be happy to know that too.

Thanks.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is just a wild guess, but maybe it'll work

write a servlet Filter that intercepts your servlet. in the doFilter() method capture the ServletOutputStream from the ServletResponse
 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

Can you tell me how to read bytes from a response object?

Thanks.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't. You'll probably need to implement a ResponseWrapper.

SearchFirst and you may find what you need.
 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to achieve it using a filter.
However I am stuck at the filtermapping in web.xml.

My url is as such:
objectHandle=Coding&actionHandle/initProjectForCoding&nextPage/coding/quickCode.grs

where object handle specifies the business object, and the action handle specifies the method to be executed. The nextpage denotes another controller call which generates the response.

This is the entry I have in web.xml


The way I have specified the filter mapping doesnt hit the filter.(I have a breakpoint in the filter and it never gets there).

Any help?
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, that isn't a valid URL. And second, it doesn't even contain the string "codingGridController", so I don't know why you would expect the filter to be invoked for it.
 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The URl works. I do get the request from the jsp.

ProxyServlet&objectHandle=Coding&actionHandle/initProjectForCoding&nextPage/coding/quickCode.grs

The "/coding/quickCode.grs " points to a method in the codingGridController.

additional mappings:


 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:... it doesn't even contain the string "codingGridController", so I don't know why you would expect the filter to be invoked for it.

 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried a different approach.
I am trying to use an Interceptor with ResponseWrapper to achieve this.

The interceptor postHandle method is invoked fine.
But the response wrapper isnt working well.
Any help?

 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Isn't working well"?

Pity about that. You might consider posting some details about why it isn't working well. Read this: ItDoesntWorkIsUseless if you don't see why you should post details.
 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried a totally different approach to achieve this.
I am using a java library to convert the html to pdf.

The pdf file is created fine but when I try to open it it says " the volume for a file has been externally altered so that the opened file is no longer valid"

Any idea why this is occuring?

 
Ranch Hand
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually this methodology won't work.
Simple way is to do by just store the output data into a object and write it into pdf response object.

Viidhya Kishore wrote:Hello All,

My requirement is to capture the html that has been rendered in jsp and convert into PDF.
I wanted help as to how to access the rendered html from the jsp.

Also, in case there is an alternate way, I would be happy to know that too.

Thanks.

 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply Vinoth.
Any code snippet to help?
 
Vt Guru
Ranch Hand
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try using iText.jar for creating pdf document
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I too want the same this, i.e to get the response in pdf format and without creating any intermediate file (which iText will create)..
please provide any example code if any of you have..
I think this can be done with streams but do not have a working code..
please help..
 
Viidhya Kishore
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used a tool called wkhtmltopdf.
wkhtmltopdf

I started with getting the html of the page using document.documentElement.innerHTML
I then sent the html from the client to the server in Ajax call.
Retrieved the html at the server and wrote out a html file.

Then used wkhtmltopdf on it.
Html File : Save as q.html in the dir.


Create a dir and download wkhtmltopdf from the link provided. I am using version 0.99
Save the html file on that dir.
Now in command prompt, cd to that dir and then execute


Look in the dir now. You will see pdf. Neat right?
 
reply
    Bookmark Topic Watch Topic
  • New Topic