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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis
  • Mark post as helpful
  • send pies
  • Report post to moderator
No, not directly.

The JSP executes on the server, long before the page gets sent to the browser where the JavaScript can be evaluated.

Please read this article to understand how JSP operates. You should not write one more line of JSP code until you understand what JSP is, and what JSP is not!

What you can do is to use JSP to dynamically create JavaScript markup to be sent to the browser. But remember, the server doesn't know anything about JavaScript, all you can do is to create the JavaScript code that will be executed later, after the page has been loaded into the browser.

For example, let's say you have a scoped variable named "fred" that contains the string "Hi there!", and you want to make this a JavaScript variable. The following markup would accomplish that:

Note that the JSP EL expression is simply evaluated in place. What is sent to the browser is:

The variable "fred" is not sent to the browser, and JavaScript knows nothing about it.

P.S. If you want to dynamically include page fragments as the result of a client action, then you'll need to use Ajax.

P.P.S. Do not be fooled by the name JavaScript — it might lead you to think that JavaScript has something to do with Java, but it does not. Aside from sharing some syntactical elements, they have nothing whatsoever to do with each other.

It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!