Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL/EL in jQuery  RSS feed

 
dzingis kan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I need to know if things like this are okay to write, it will work, but I don't know if it is bad practice

Attribute categoryList (its json) is set in servlet which forwards to JSP


This is EL in jquery, on JSP


I need that data in jquery variable to use it later, to display some more info about certain category and similar, so is there better way to do it ?
It feels really stupid but it works, so can someone give me advice on this ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66196
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as you understand that the substitution happens on the server before the page is sent to the browser, and that the EL reference is not resolved on the client when the JavaScript is run.
 
dzingis kan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I know, javascript file ends up looking like its hardcoded with that data, I just didn't know, maybe there are some reasons unknown to me why this would be bad, and I couldn't think of another way of getting that data from server side to jQuery variable, I mean there are ajax calls, but then I would have to call another servlet and I wouldn't need to use attribute.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66196
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the other way is to grab it with Ajax; but that has its overhead.

Back when I was still using JSP, I used to do the same sort of thing all the time. I think it's fine as long as you understand how it's working under the covers.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Back when I was still using JSP,

This caught my eye. What are you using now?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66196
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the past couple of years I've been writing SPAs¹. The server-side components are all RESTful APIs which have no views, so no JSP.



¹ Single-page web application
 
dzingis kan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the answers, I'll mark it as resolved.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!