Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem using jstl in javascript

 
Bradusca Luisa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, in my jsp page I have:


And in my javascript function:


And it doesn't takes the index in ${}, but if I use alert(index) it recognize it. What is wrong?
Thanks in advanced
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand. What did you mean to happen, and what actually happened?

Let me remind you that the JSP (including JSTL) runs on the server and generates HTML, which may include Javascript. You didn't say whether this Javascript code was generated by the JSP or not. Then later, after that is all finished, the Javascript may run in the browser, on the client. You can't expect JSTL to do anything at this point.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As the code contains Struts tags, this has been moved to the Struts forum. Please be sure to post any questions containing Struts artifacts to that forum.
 
Bradusca Luisa
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I don't understand. What did you mean to happen, and what actually happened?

Let me remind you that the JSP (including JSTL) runs on the server and generates HTML, which may include Javascript. You didn't say whether this Javascript code was generated by the JSP or not. Then later, after that is all finished, the Javascript may run in the browser, on the client. You can't expect JSTL to do anything at this point.


Hi Paul, thanks for your reply!
Yes, the javascript code was generated by the JSP, and now I understant why ${} couldn't see my index variable because el is executed at server side and javascript at client side.
But how I can do what I meant to do that is: user selects a bean from a select option and I want to appear information about that bean in a div/span..-wich is:name,address,email and so on.(I allready have all the list generated in server side and also I have an index property so that I can choose easier listOfBeans.get(index).)
Thanks in advanced!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You either need to use Ajax, or build up all the JavaScript you need on the server side.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic