IntelliJ Java IDE
The moose likes JSP and the fly likes Can I use JSP to put info into Javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Can I use JSP to put info into Javascript?" Watch "Can I use JSP to put info into Javascript?" New topic
Author

Can I use JSP to put info into Javascript?

Toni Howlett
Greenhorn

Joined: Jan 18, 2012
Posts: 25
Will this work?

I plan to use JSP to pull some values from my properties file, and I want to populate an array with those values.

So could I have JSP in my <script> tags?
(In my mind, this will work - but before I go spending time doing it and it doesn't work I was just going to ask. I know that JSP runs first and only once)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

Sure, you could have JSP code inside a <script> element. But as you already know, that JSP will be evaluated before the browser even sees the <script> element. So just make sure your JSP code generates a Javascript assignment statement which assigns an array to a variable.
Toni Howlett
Greenhorn

Joined: Jan 18, 2012
Posts: 25
Alrightie - Awesome!! Thanks
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

You might find this article helpful in understand how JSP operates in this regard.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
 
subject: Can I use JSP to put info into Javascript?
 
Threads others viewed
JSP-is it required?
about browser cache
internalization problem URGENT AGAIN :(
can't acces fieldcontent Clicking on a actionUrl Link on a JSP
jsp methods to database class synronized
IntelliJ Java IDE