Struts 1.1 -- Generating unique URL for each JSP

D

Duke Hamacher

Hello:

I have been having problems with client caching on my largely dynamic
Struts web application. I have looked at several solutions and the
one I would like to implement generates a unique (millis) number and
attachs it to the URL and forwards, so that the browser will never
encounter the same file twice, even though they are different in name.

Does anybody follow me so far? I do not want to depend on HTTP
headers or other comparisons. I just want every single URL sent to
browsers to be unique request after request for some of my pages.

I have studied the solution for a few days but I can't seem to figure
out how I could attach a number to a URL like ... xxxx.jsp;76622363 or
.... xxxx.jsp;num=38236623 or ... xxxx.jsp?num=843927333 , etc.

I am fairly new to Struts and web programming, so belt me if this
sounds insane.
Thanx.

Duke
 
V

VisionSet

Duke Hamacher said:
I have been having problems with client caching on my largely dynamic
Struts web application. I have looked at several solutions and the
one I would like to implement generates a unique (millis) number and
attachs it to the URL and forwards, so that the browser will never
encounter the same file twice, even though they are different in name. ....
I have studied the solution for a few days but I can't seem to figure
out how I could attach a number to a URL like ... xxxx.jsp;76622363 or
... xxxx.jsp;num=38236623 or ... xxxx.jsp?num=843927333 , etc.

It's a while since I've worked on that end of my web app and it's my 1st
struts app.

But it seems to me an elegant solution would be in your ActionForm subclass
to have this:

long num;

public String getNum() {
if(num == 0) num = new Date().getTime(); // or however you generate your
unique id

return Long.toString(num);
}

If you are using DynaActionForms you will have to subclass and filter for
that particular parameter in the get()
 
D

Dobromir Gaydarov

Duke Hamacher said:
Hello:

I have been having problems with client caching on my largely dynamic
Struts web application. I have looked at several solutions and the
one I would like to implement generates a unique (millis) number and
attachs it to the URL and forwards, so that the browser will never
encounter the same file twice, even though they are different in name.

Did you follow the standard ways to instruct proxies and browsers not to
cache the page?
Did you check the client browser settings?

If you did and it still does not work, try using POST method to send your
requests, since that is normally not cached.

BTW, none of this has anything to do with Struts.
Does anybody follow me so far? I do not want to depend on HTTP
headers or other comparisons. I just want every single URL sent to
browsers to be unique request after request for some of my pages.

I have studied the solution for a few days but I can't seem to figure
out how I could attach a number to a URL like ... xxxx.jsp;76622363 or
... xxxx.jsp;num=38236623 or ... xxxx.jsp?num=843927333 , etc.

I am fairly new to Struts and web programming, so belt me if this
sounds insane.

Yes, it does sounds insane.

Regards,
Dobromir
 
S

Sudsy

Duke said:
Hello:

I have been having problems with client caching on my largely dynamic
Struts web application. I have looked at several solutions and the
one I would like to implement generates a unique (millis) number and
attachs it to the URL and forwards, so that the browser will never
encounter the same file twice, even though they are different in name.

Have you configured your struts-config.xml properly? I use this:

<controller
contentType="text/html;charset=UTF-8"
nocache="true"
processorClass="org.apache.struts.action.RequestProcessor"/>

That's to tell struts to include the HTTP header "Pragma: no-cache"
in all responses. Your browser clients should observe that directive.
All the ones I've tried handle it correctly.
YMMV
 
D

Duke Hamacher

Sudsy said:
Have you configured your struts-config.xml properly? I use this:

<controller
contentType="text/html;charset=UTF-8"
nocache="true"
processorClass="org.apache.struts.action.RequestProcessor"/>

That's to tell struts to include the HTTP header "Pragma: no-cache"
in all responses. Your browser clients should observe that directive.
All the ones I've tried handle it correctly.
YMMV

Sudsy:

I use a servlet filter to wrap the response and set the
"Cache-Control" header to "no-cache". It doesn't work and I have been
told by a friend in the industry that browsers do not necessarily obey
this header when the pages are mainly templates for data (like mine).
I will try setting Pragma to no-cache.
Thanx.

Duke Hamacher
 
D

Duke Hamacher

Dobromir Gaydarov said:
Did you follow the standard ways to instruct proxies and browsers not to
cache the page?
Did you check the client browser settings?

I use a servlet filter to wrap the repsonse by setting the
"Cache-Control" header to "no-cache". It doesn't work. A friend of
mine in the industry tells me most browsers do not obey the
"Cache-Control" header when pages are largely templates for data (like
mine). I haven't tried setting the Pragma header and I will do that.
If you did and it still does not work, try using POST method to send your
requests, since that is normally not cached.

I will make sure everything is POSTed.
BTW, none of this has anything to do with Struts.

Yes, it does sounds insane.

Regards,
Dobromir

Well, I know people do it (derive unique URLs) and I think it is a
more elegant solution than checking modified-dates or relying on the
browsers of the world, who in general have trouble deciding what
specifications to follow. But I appreciate all the advice.

Duke Hamacher
 
S

Sudsy

Sudsy:
I use a servlet filter to wrap the response and set the
"Cache-Control" header to "no-cache". It doesn't work and I have been
told by a friend in the industry that browsers do not necessarily obey
this header when the pages are mainly templates for data (like mine).
I will try setting Pragma to no-cache.
Thanx.

Duke Hamacher

I should have noted that Cache-Control was introduced in HTTP 1.1.
If you're sending it to a browser which wants an HTTP 1.0 response
then it can justifiably ignore the directive.
Without digging into the Tomcat code, I would expect that it would
add the appropriate headers, i.e. Pragma: nocache in the case of a
1.0 response and Cache-Control: no-cache for 1.1 responses.
I just prefer to leave these nasty little details to the framework
don't you know.
 
L

Lone Droid

I have studied the solution for a few days but I can't seem to figure
out how I could attach a number to a URL like ... xxxx.jsp;76622363 or
... xxxx.jsp;num=38236623 or ... xxxx.jsp?num=843927333 , etc.

I am fairly new to Struts and web programming, so belt me if this
sounds insane.

I don't know if the way you want to proceed is the best way to proceed
to achieve your goal, but your idea is definitely sound and feasible.

As a matter of fact, I have a Webapp server serving uniques URLs for
*every single page*... Every single GET or POST HREF is generated
before
the page is served to the client and hence every single URL is
different.

I did for security purpose : basically I am signing
every single URL with a cryptographic hash to prevent URL
modifications.

Now what you do with unique URLs is up to you : in my case some unique
URLs can be bookmarked, others don't. Some request have to take place
during the same session, others don't. Some request have to take place
from the same client IP adress, others don't, etc.

This is working flawlessly, it is in use on a production server, and
URLs sent to the client are definitely unique...

The *only* URL that is not unique is the main URL of the site !

Do a search on groups.google.com on "lonedroid" if your interested or
mail me...

See you later on cljp,

Lonedroid
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top