Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I use a javascript var in my jsp?  RSS feed

 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody;
I imported a javascript file in my jsp and I need to use a global var defined in js file.
How can I do that?
Yhank You!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From where? Other JavaScript code? Or are you still writing Java code in your JSPs (very old-fashioned!) and want to access it there?

If the former, no problem. The fact that the page is a JSP is moot as far as the JavaScript is concerned.

If the latter, you can't. Java code in a JSP (which you should not be writing) runs on the server long before the page gets sent to the browser where the JavaScript is interpreted. If that's confusing to you, maybe this article will help.
 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so, if I need to use var in a java code included in my jsp there's no way. <% %>
right?

Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read the article?
 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
I'm working on an existing prject.
There's a javascript file that perform open and close menu actions (struts-menu).
I have to change menu tooltip in "CLOSE" if the menu is opened and "OPEN" if the menu is closed.
The code that creates menu and set the tooltips is included in a scriptlet in a jsp page.
How can I retrieve the information on menu status (open or close) and use it to set the tooltip in my java code?

Thank you very much.

p.s.
sorry but english is not my first language
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!