Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

calling javascript from JSP

 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I saw some sample JSP code calling javascript. The JSP includes a few javascript, but when it invokes a javascript method it just calls like

javascript:anMethod(...)

It does NOT specify which javascript code it is. so how does this work ? is it going to search each of the javascripts this JSP includes and locate the one that has this method name ?? what if two javscript have the same method name ??

More strange thing is -- I saw another sample JSP code doing the similar thing but it even doesn't include any javascript file name in it. Surprisingly, its

javascript:someMethod(..)

works well. So I am wondering --- Does it mean the application will automatically search all the javascripts located in the root directory and locate the one that has this "someMethod" method ?? again, what if two javascripts have the same method name ??
 
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP cannot call JavaScript.

However, once the JSP is is rendered as HTML and sent to the browser, JavaScript can be executed in the normal way.

And for the JavaScript to work, the function must be loaded into the page. There is no automatic searching of files.
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is possible that javascript:someMethod() will work even when there are no *.js files included because there are many methods available by default, e.g. javascript:alert('Hi there!') will work without any *.js inclusions.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic