views:

262

answers:

3

I'm writing a testing utility- I want to show multiple finished HTML "pages" in a single browser window.

Is this possible? I'm using Java Servlets.

For example, normally the user goes to a utility screen, fills in a bunch of fields and POSTS this to my servlet, which builds up a full HTML stream based on their input and writes it to HttpServletResponse.getWriter(). When the user views source, they get a <html> ... </html>.

What I want to do is allow users to request multiple "screens" and get the results in a single web page where you'd scroll down to see the 2nd, 3rd, etc. screens, maybe there is some kind of divider in between. I thought of frames or iframes, but didn't have luck. I have seen where I can write my big html stream to a javascript variable, then use document.write to dump it into the iframe. But that seems pretty awkward, and I'd have to be really careful about escaping quotes and stuff.

+1  A: 

You will have to use iframes or frames to do this. A single web page can only contain one set of html tags and thus one html page.

Another idea would be to render the page by your script and then capture a picture of it and then have a page containing images. You will of course loose all interaction with the page.

MitMaro
+1  A: 

Just leave out the <html>/</html> tags for each page and wrap the whole thing inside a single large ....

Like this maybe:

<html>

[page1Content]
<hr />
[page2Content]
<hr />
[page3Content]
<hr />

</html>
Nate Bross
This will work well with simple pages if you parse out everything not inside the pages body tag. However if the page contains any css styles or Javascript then the page will probably break. Also if he is concerned with validation of the page then there is a good chance using this method will not validate. :)
MitMaro
Agreed, my method is a quick and dirty approach.
Nate Bross
Right, but I want each page to potentially have separate CSS definitions in the header, etc. I think the iframes is the way to go, just not sure how to get my content inside the frames without specifying it via the src= attribute.
Seth
+1  A: 

I'm not sure what you're trying with your frames, but I imagine frames should work OK for what you've described.

Instead of trying to post to more than one URL from your form, you just post to a servlet that returns a page with the frameset, and each frame has a source that points to one of the URLs you want to test. For example:

<form action="testServlet" method="post">
    <input type="text" name="someValue" />
</form>

The testServlet then returns a page with this content:

<frameset rows="33%,33%,33%">
    <frame src="testUrl1?someValue=value">
    <frame src="testUrl2?someValue=value">
    <frame src="testUrl3?someValue=value">
</frameset>

The only problem with this is that you're doing a GET instead of a POST, but that's easy to get around. All you would need do is to implement the doGet method within your servlets and just call doPost from within doGet.

Ickster
this approach might work for me, thanks for the tip!
Seth
Glad to help. Feel free to ask for clarification on anything if you need it.
Ickster