aspose file tools*
The moose likes JSP and the fly likes Javascript import fails when using EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Javascript import fails when using EL" Watch "Javascript import fails when using EL" New topic
Author

Javascript import fails when using EL

Mandar Lad
Greenhorn

Joined: Sep 05, 2012
Posts: 2
Hi Friends,

Below is snippet from a JSP file.
Earlier I had used scriptlet (<%=request.getContextPath()%>) to populate the context path as shown in [A].
All 3 javascript files were being imported.

[A]
<script language="JavaScript1.2" type="text/javascript" src="<%=request.getContextPath()%>/js/a.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="<%=request.getContextPath()%>/js/b.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="<%=request.getContextPath()%>/js/c.js"></script>

I replaced the `contextpath` population using EL(Expression Language) as shown in [B].
I also modified javascript files a.js and c.js and added some functions.
I redeployed my application ear. I see that the new file a.js is reloaded in the browser (IE) cache, but c.js remains unchanged.

[B]
<script language="JavaScript1.2" type="text/javascript" src="${pageContext.request.contextPath}/js/a.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="${pageContext.request.contextPath}/js/b.js"></script>
<script language="JavaScript1.2" type="text/javascript" src="${pageContext.request.contextPath}/js/c.js"></script>

Why does this happen? (I suspect that javascript errors in one of these external files which is preventing c.js from loading.)
Has anyone come across such a scenario. Please reply asap. Thanks.

Regards,
Mandar
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61199
    
  66

If the HTML delivered to the browser is the same, there should be no differences in behavior -- at least not caused by the JSP.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
So that would imply you view source on the generated page, make sure that the ${el expressions} are being evaluated and if not, then check out the FAQ for EL not working as expected
Mandar Lad
Greenhorn

Joined: Sep 05, 2012
Posts: 2
Hi Friends,

I have found the problem. JavaScript file c.js had some compilation problems like missing semi colon etc.
After removing those issues, file c.js also gets reloaded in browser.
So I would conclude that when EL is used to import javascript files in JSP, compilation checks are performed on each file.
This is not true when scriptlets are used.

Regards,
Mandar
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61199
    
  66

Mandar Lad wrote:
So I would conclude that when EL is used to import javascript files in JSP, compilation checks are performed on each file.
This is not true when scriptlets are used.

Your conclusion is not correct. JavaScript files are not checked by the JSP container at all regardless of whether you use the EL or obsolete scriptlets.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript import fails when using EL