Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Page Source In The Servlet

 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All;

Anyone know of an easy way to get the page source (as in HTML) from a page that posts to a servlet?

The reason I'm asking is I would like to create HTML table in JSTL that could be used in another part of my application. If the servlet could some how get this generated HTML I would be in business.

Do I have to actually locate the file on the server and parse it? What if the html page is generated with a JSP (as in this case)?

Thanks,

Luke
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's like pulling yourself inside out.

If you want to reuse the JSP fragment that builds the table, a much more conventional -- and considerably less hair-pulling -- means of doing that is with a custom tag or an include file.
[ June 14, 2005: Message edited by: Bear Bibeault ]
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick response.

Can you kindly expand a little bit on how I could use an included file to get JSP output in the servlet?

Thanks,

Luke
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My point was that you don't want to save the JSP output and try to reuse the output.

If you want the table to be the same in both places, use the same JSP fragment to generate it. By placing the fragment in an include file (or within a custom tag) you don't need to copy and paste any code, and can use it from multiple locations.

Why do you want to save the output for later display rather than just generating it on the fly? That's a real hinky thing to try to be doing.
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I am after is this.

The client uploads photos that get written into a table in the JSP (a gallery). As they upload they can check how it looks, changing the photos as they wish.

The photo names and locations are stored in a DB on the server.

That same table is written as part of a report to a file on the server by a class in the system. It looks up the locations of the files from the DB and generates the HTML to create the photo gallery.

Right now I'm building the table in JSP so the client can see it, than creating it again in a java class so it can be written into the report.

It would be nice if I could consolidate the 2, ideally creating all HTML in the JSP and none in Java.

I hope this gives a clearer picture.

Luke
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, so you want to use the JSP engine as a report formatter as well. I take it the report file is an HTML file?

Do you want to do the "report capture" as part of a client-initiated HTTP request? Or is this something that is initiated by another means?

You may want to look into Filters and the HttpServletResponseWrapper as a way of cpaturing the output.
 
Luke Shannon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The report file is an HTML.

The generation of the report is initiated by other means (not the submission of the form we are discussing).

Thanks,

Luke
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic