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
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.
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
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, 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.
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