wood burning stoves 2.0*
The moose likes Servlets and the fly likes Getting Page Source In The Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting Page Source In The Servlet" Watch "Getting Page Source In The Servlet" New topic
Author

Getting Page Source In The Servlet

Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
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


Luke
SCJP
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61457
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
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

Joined: Jan 10, 2002
Posts: 61457
    
  67

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

Joined: Sep 30, 2004
Posts: 239
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

Joined: Jan 10, 2002
Posts: 61457
    
  67

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

Joined: Sep 30, 2004
Posts: 239
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting Page Source In The Servlet