Suchi wrote:
> Hi!
>
> I have tried the following, I have a parent html page, say Parent.html which has
>three frames in it, respectively serving servlet1, servlet2 and servlet3. Now on
>servlet3's html page I have a button that loads servlet4 in frame 3. I click on that
>button and servlet4 is loaded in frame 3. I hit the 'refresh' button of the browser.
>Frame 1 is loaded with servlet1, frame 2 with servlet2 and frame 3 with servlet4 as
>expected. I hit the browser back and I have servlet 3 in frame 3. Here too if I
>refresh the pages are loaded right.
>
> Now, I convert the Parent.html to Parentservlet which does nothing but puts up the
>Parent.html page. Now I load Parentservlet. Frame1 -servlet1, frame2-servlet2,
>frame3-servlet3. I click on button on servlet3 which loads servlet4 in frame 3. Now
>the 'QUESTION PART'--- I hit refresh here, expecting frame1-servlet1,
>frame2-servlet2, and frame3-servlet4. But what I get in frame3 is servlet3.
>
> The only difference in the two approaches is that the parent is HTML in one and
>SERVLET in another.
>
> Could anyone say why this difference in behaviour and what needs to be done to get
>the same behaviour in servlet as the HTML.
>
> Any information in this regard will prove very helpful.
>
> thanks!
>
> Suchi
>
Interesting timing on this question, given the ongoing discussion about
getLastModified() !!!
When your browser requests a URL that is already in its cache, it has remembers the
pages's modified date/time when it was first loaded, and can send an
"If-Modified-Since" header with the GET request. If the server can tell that the page
has not been modified since this specified time, it sends back a NOT MODIFIED response
(HTTP status code 304) instead of the page. The browser can then use it's cached copy.
In the case of a static HTML page, your web server can compare the last modified date
of the file against the If-Modified-Since value, and decide that it hasn't changed.
Therefore, the frame contents are individually refreshed from your current state:
servlet1, servlet2, and servlet4.
But in the case of the servlet, let's assume first that you did not implement
getLastModified() -- which is probably the case. The default value of -1 tells the
servlet engine that it needs to send the contents of the generated page again, which
of course loads the original frameset. The frameset loads the original contents
(servlet1, servlet2, and servlet3) -- thus resulting in the behavior you observed.
So how do I change this? Well, you would need to implement getLastModified() using
one of a couple different strategies:
* You could remember when you last sent the
generated parent page to *this* user by recording
something in his/her session.
* You could pick an arbitrary time, such as when the
servlet engine was started up, and call that the
getLastModified() time for the parent page,
for all users. Clients who call this page the first
time (i.e. it's not in their cache) will get the page
marked with this timestamp -- from then on,
they will get back NOT MODIFIED responses when
they try to reload this page.
Alternatively, you could dispense with getLastModified() as a separate calculation,
and just return an SC_LAST_MODIFIED status yourself from the doGet method if you
decide that the user's current version of the page is still valid. (Side note to
Geoff -- here's a way to deal with your concerns about sharing state between
getLastModified() and doGet()).
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html