Last Modified date of a remote JSP file - URGENT

Hi All,

I am getting the last Modified Date for all types (.html, .txt etc.) of remote files except JSP file. Here is the code I am using:

URL url=new URL("http://www.mysite.com/index.html");

URLConnection uc=url.openConnection();

Date d=new Date(uc.getLastModified());

System.out.println(d);

Only for JSP files I am getting 0 as return value of getLastModified(). Can anybody explain why is it so.

Is it the case that JSP file is not setting the lastModifiedDate response header.

Please help. This is URGENT.

Thanks in advance.

[680 byte] By [arunkumar504a] at [2007-11-27 10:41:06]
# 1

I don't see what having a 'last modified' date for a jsp would mean. I suspect that the zero is the value returned if there is no 'last modified' header.

You could always test for zero and then use the current date (new Date()).

P.S. Please don't flag things as urgent.

Message was edited by:

sabre150

sabre150a at 2007-7-28 19:10:44 > top of Java-index,Core,Core APIs...
# 2

Hi,

In case of JSP file it is always returning 0. So taking current date will not give me the last Modified Date.

arunkumar504a at 2007-7-28 19:10:44 > top of Java-index,Core,Core APIs...
# 3

> In case of JSP file it is always returning 0. So

> taking current date will not give me the last

> Modified Date.

One of us is missing the point. For a static HTML page the meaning of the 'last modified' date is obvious - it is the data it was last modified but what would be the meaning of 'last modified' date in the case of a JSP. The content provided by a JSP may be different every time it is invoked.

You could argue that the 'last modified' date should be the current date/time but since zero is an easy value to handle and is unlikely to suffer from problems that result from small differences in clock settings it seems to be reasonable value.

sabre150a at 2007-7-28 19:10:44 > top of Java-index,Core,Core APIs...
# 4

Hi,

I think its not because JSP generates dynamic pages and the result can be different each time. Html files can also be dynamic.

I think its because of response headers not set for JSP's automatically.

Run & check the code once to see what's happening even if there is no scriplet code in JSP and only HTML code.

arunkumar504a at 2007-7-28 19:10:44 > top of Java-index,Core,Core APIs...
# 5

So, if it's your JSP then go ahead and set that header data, it's up to you if you want to do that. Just because it doesn't do it by default does not mean it's a bug or anything. LastModified is an optional entity header field. It does not have to be set.

If they are not your JSP's, then tough luck. As I said it is an optional field, so you cannot force other people to set it.

masijade.a at 2007-7-28 19:10:44 > top of Java-index,Core,Core APIs...
# 6

Hi Masijade,

I have access to the JSP. As you said I need to set the header explicitly. OK

But now the problem is what should I put in setDateHeader() method for date parameter. I can't put System.currentTimeMillis() coz this will give me today's date everytime.

How to set the response Header in such a way that I always get the lastModifiedDate of that JSP file.

Thanks

-AKJ

Message was edited by:

arunkumar504

arunkumar504a at 2007-7-28 19:10:44 > top of Java-index,Core,Core APIs...
# 7

> How to set the response Header in such a way that I

> always get the lastModifiedDate of that JSP file.

>

I have no idea BUT this still does not make sense to me since JSP normally provide different output each time they are invoked. If your JSP is providing the same response each time then you might want to consider converting it to a static HTML file.

sabre150a at 2007-7-28 19:10:44 > top of Java-index,Core,Core APIs...
# 8

... and if your client application is relying on the presence of this header in a JSP it has a major conceptual flaw.

ejpa at 2007-7-28 19:10:44 > top of Java-index,Core,Core APIs...
# 9

Use what you want to use.

If you only want the date of the last change to the actual JSP (or any other string you can set yourself) then simply use a date string that you set yourself when you make changes to the jsp.

If you want the date that the data changed, then your data will need to provide that date and you will have to read it somehow. For example, if you are reading your data from a atable, and that table has a timestamp field, then use the newest timestamp value.

In short, set it to anything you want to set it to.

Edit: But as mentioned above, you should not be relying on this info. It doesn't make much (if any) sense.

masijade.a at 2007-7-28 19:10:44 > top of Java-index,Core,Core APIs...