You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Emmanuele Sordini <em...@GMAIL.COM> on 2009/02/23 16:45:48 UTC

Problems with javascript files in Struts-based webapp

Dear List,
I'm writing you hoping to get some insight on a problem that's been haunting
me for quite a while now. I've tried searching the ML archives but I have
not come up with anything useful.

I have a Struts-based web application which makes use of the Tiles framework
and of some dynamic Javascript libraries (such as OpenLayers, for example,
but I think this issue applies to pretty much any JS file). In a "normal"
JSP page I just included the script file, e.g.:

<script language="Javascript" src="/scripts/OpenLayers/OpenLayers.js"/>

which means:

"load for the Javascript file located at
<address>/scripts/OpenLayers/OpenLayers.js"

and everything would work fine. But putting the very same statement in the
jsp tile of the new web server, does not work at all. What I've found with
Firebug is that for some reason it throws the absolute path away and looks
for OpenLayers.js in another location:

<address>/lib/OpenLayers.js

The OpenLayers library is made up of a complex directory tree, like this:

<rootdir>/OpenLayers.js
<rootdir>/Gears/a.js
<rootdir>/Gears/b.js
<rootdir>/BlahBlah/c.js

even worse, the JavaScript structure is ignored altogether, and the browser
tries to load the files as follows:

<address>/lib/OpenLayers.js
<address>/lib/a.js
<address>/lib/b.js
<address>/lib/c.js

If I put the library in the "/lib" path, only the first JS file gets loaded
correctly but the others don't, thereby causing the application to fail.
Looks like there is a serious problem with the way Struts rewrites and/or
handles relative and absolute paths.

I tried hard-wiring the path in the page or using the <html:base> tag in the
main page, but all my attempts have been unsuccessful so far.

Any help on this issue will be highly valued: thank you very much in
advance.

Emmanuele Sordini
-- 
View this message in context: http://www.nabble.com/Problems-with-javascript-files-in-Struts-based-webapp-tp22163997p22163997.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problems with javascript files in Struts-based webapp

Posted by Dale Newfield <da...@newfield.org>.
Emmanuele Sordini wrote:
> http://www.nabble.com/Loading-and-Calling-Java-Script-in-Struts-td20623678.html

None of those suggestions help you?

What is the jsp code you're writing?  What is the path that the browser 
receives?  I'm willing to bet that either you're not using the jstl 
version you think you're using, or you're asking tiles to do more than 
you really want.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problems with javascript files in Struts-based webapp

Posted by Emmanuele Sordini <em...@GMAIL.COM>.

DNewfield wrote:
> Many browsers have issues with this--you'll have better luck if you 
> convert this to an (empty) container tag:
Thanks but unfortunately that was already the case, and it doesn't work.


DNewfield wrote:
> The server doesn't control how the browser interprets the code it 
> provides.  If the browser isn't doing what you expect, make sure that 
> the browser is receiving the instructions you expect it to receive. 
> Look at the source of the page being displayed (which may differ from 
> the DOM model that firebug shows as the DOM can get substantially 
> changed from the original html code provided by the server).  Make sure 
> that the document base isn't redefined somewhere, and make sure that the 
> paths you expect to be listed are what is being transmitted to the client.

The DOM I get with Firebug looks very much like the (generated) source code
I can view with the browser's inspector. Looks like Struts is "processing"
the path information in a way I've never seen before (kind of relative to
the page's context path), and the use of tiles probably brings in an
additional level of complexity. 

Please check out the following:

http://www.nabble.com/Loading-and-Calling-Java-Script-in-Struts-td20623678.html

I'm not the only one having problems, but unfortunately my case is probably
more complicated as the JS libraries I'm including are made up of many files
arranged in a complex directory structure. Rewriting the script URL is fine
for the master include file ("OpenLayers.js"), but does not work for all the
others it contains.

Regards
Emmanuele
-- 
View this message in context: http://www.nabble.com/Problems-with-javascript-files-in-Struts-based-webapp-tp22163997p22180963.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problems with javascript files in Struts-based webapp

Posted by Dale Newfield <da...@newfield.org>.
Emmanuele Sordini wrote:
> In a "normal"
> JSP page I just included the script file, e.g.:
> 
> <script language="Javascript" src="/scripts/OpenLayers/OpenLayers.js"/>

Many browsers have issues with this--you'll have better luck if you 
convert this to an (empty) container tag:
<script language="Javascript" 
src="/scripts/OpenLayers/OpenLayers.js"></script>

The server doesn't control how the browser interprets the code it 
provides.  If the browser isn't doing what you expect, make sure that 
the browser is receiving the instructions you expect it to receive. 
Look at the source of the page being displayed (which may differ from 
the DOM model that firebug shows as the DOM can get substantially 
changed from the original html code provided by the server).  Make sure 
that the document base isn't redefined somewhere, and make sure that the 
paths you expect to be listed are what is being transmitted to the client.

-Dale

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org