Bookmark Topic Watch Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
A lot of questions get asked in the JSP forum about mixing JSP and JavaScript. The simple answer is that it just cannot be done!

JSP is a server-side templating system that creates an HTML page (or other text document) on the server. Anything in this page that is not a JSP action or directive is simply template text that is ignored. HTML, CSS, and JavaScript code is just so much gobble-dee-gook to the JSP engine. It doesn't know anything about it, and it is simply passed into the response as is.

Once the HTML page has been formatted, it is sent to the client (usually a browser) for evaluation and display. All JSP-ness is completely gone at this point.

It is at the browser that the JavaScript is evaluated. And the browser doesn't even know that the page was generated by a JSP, let alone interact with it.

So, the JSP executes on the server and doesn't pay any attention whatsoever to JavaScript code and other page markup. And the JavaScript executes on the client, where even the fact that JSP is being used is unknown.

Never shall they meet! It's even worse than Romeo and Juliet, who at least got to get it on for a short time.

For more information about exactly how a JSP is processed, read The Secret Life of Java Server Pages


JspFaq
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic