• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

struts + static content on http server

 
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all-
I've two questions re: splitting up static and dynamic content in a struts app.
Seems that struts won�t look for static content on the http server: I�m playing with the struts-example app which has two static resources: struts-powered.gif and tour.htm.
I remove them from my WebApp (war) and put them on the http server. I load the war and it picks up the gif just fine. But it can�t find the tour.htm and is trying to load it via the container.
This is due to:
<html:link page="/tour.do">
and tour.do is mapped to tour.htm as a global forward:
<action path="/tour" forward="/tour.htm"></action>
If I change �tour.do� to �tour.htm� in the link tag, it loads my the htm from the content server.
This is what I want.
My questions are:
1. Did I do the right thing here? Doesn�t seem to be a big deal to code my app this way.
2. Am I going to get into trouble with other static resources in struts?
Thanks,
Max Tomlinson
 
author
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Max,
You did the right thing
However you need to be aware of some more changes needed in larger Struts applications.
Replacing *.do for the static content with direct URL for the static content is the right step. However that is not all.
Here is my experience regarding splitting of static and dynamic content for several production deplyments I have in the past using Struts.
1) Do not use the <html:base/> tag. This tag will set the base href to be the url to the current page. Here is a sample base href.
<base href=�http://www.foobar.com:8080/App1/abc/CustomerDetail.jsp�/>
"App1" is the web application context and "abc" is the directory containing the jsp.
When seperating static and dynamic contents, the base href should ideally be
http://www.foobar.com/App1.
In such situations (as is the case in all production deployments), I roll out my own BaseTag that generates the above URL.
(In your case the gif came up fine even without making this change because your JSP was at the top level - not under subfolders.)
2) Next create a doc root in the Http Server with the name "App1" and move static content there.
3) If there is a suffix mapping (*.do) used to redirect to a static content, replace it with the URL for static content.
Hope this helps.
 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Srikanth-
Thanks for taking the time for this excellent response. I AM going to have to watch out for this second issue as I have been tasked with splitting up four WebApps. When you say you 'create your own base tag' do you mean you wrote a tag to set the jsp base?
thanks again
Max
 
Srikanth Shenoy
author
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Max Tomlinson:
Srikanth-
When you say you 'create your own base tag' do you mean you wrote a tag to set the jsp base?
thanks again
Max


Exactly.
The easiest way is to subclass the BaseTag in Struts and override the doStartTag as follows:

If you are using hardware load balancers external to the application server, the above logic will not work, since the SSL is handled at the load balancer level and the application server only sees http and yet the port might be 443.
 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so this is getting tricky. Can I simply omit the base tag?
I bought a copy fo your book, BTW, an email. It's v good so far.
Max
 
Srikanth Shenoy
author
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Max,
The customized BaseTag was the "last nail in the coffin" - so to speak in seperating the static and dynamic content onto web server and app server respectively.
The code I posted compiles and works. I found it very handy.
You might want to give it a shot.
 
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just found out we are using load balancers in front of our servers which means this won't work, though, right?
 
Srikanth Shenoy
author
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are in the same boat as I am at a client site now
I still use the customized BaseTag even for this scenario. The logic is different however.
There is no way for the application server to know if it is http or https by using the request.getScheme() call. Similarly there is no way to know whether the port 80, 443 or any other port is used.
Hence I created a properties file per deployment environment and the custom base tag reads the properties file to find if http or https is used and also for the port.
I know this is not a great solution, but there is no other way either!!!
Cheers
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic