• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What JSP compiler does with included Javascript?

 
Jayavardhan geepi
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 207
Eclipse IDE Firefox Browser jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jayavardhan geepi
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 207
Eclipse IDE Firefox Browser jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic