It's not a secret anymore!*
The moose likes JSP and the fly likes What JSP compiler does with included Javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "What JSP compiler does with included Javascript?" Watch "What JSP compiler does with included Javascript?" New topic
Author

What JSP compiler does with included Javascript?

Jayavardhan geepi
Ranch Hand

Joined: Jul 21, 2010
Posts: 66
Hi,

We know that we include external javascript file or inline javascript code inside a jsp very commonly.

I experienced that expression language inside javascript like



works perfectly fine.

I'm wondering how it works and what JSP compiler does with included javascript.

Can some one explain please?


Thanks
Jay
Piyush Joshi
Ranch Hand

Joined: Jun 10, 2011
Posts: 207

Javascript is executed at the client side, in the browser. JSP Engine does not do anything to Javascript. It treats the Javascript the same way as it treats the html, i.e. as plain text. And as it evaluates EL expressions inside html tags, in the same way it evaluates EL expressions inside Javascript.


Piyush
Jayavardhan geepi
Ranch Hand

Joined: Jul 21, 2010
Posts: 66
Thanks Piyush.

So does browser executes EL? Not JSP Compiler?
Does JSP compiler puts EL as it is in the converted servlet?
Jayavardhan geepi
Ranch Hand

Joined: Jul 21, 2010
Posts: 66
Oh.. I think Got it now.

JSP compiler evaluates all ELs inside html tag
which may be in javascript or jsp.

Piyush Joshi
Ranch Hand

Joined: Jun 10, 2011
Posts: 207

Yes..
JSP Engine evaluates all ELs in the JSP page. It does not matter whether they are inside an html tag or Javascript.
Every JSP is translated to Servlet. So you can check, what the JSP Engine has done to your page by reading the source code of the translated Servlet. In Tomcat you can find the source code in "tomcat\work\Catalina\localhost\YourWebAppName\org\apache\jsp".
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

Anything that's not a JSP element is completely ignored during JSP processing and is simply template text that is passed to the browser unchanged.

The reason your example "works" is that the El expression is replaced within the template text with its value and the result is sent to the browser. You can see the result by doing a View Source in the browser.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What JSP compiler does with included Javascript?