Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Embedding JSP tags in Javascript  RSS feed

 
Bai Shen
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a piece of jQuery code that sets the background image. I need to set the context path so it's not hard coded. I did it with the following JSP tag.



But I can't figure out how to get that to play nice with the javascript.



I need to place the context path before the /images in the url.

TIA.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think what you want to use is the <c:url> JSTL tag. Assuming your JavaScript is embedded in your JSP page, you should be able to just stick the tag into the JavaScript itself. For example, the following tag: will result in a URL to the image which includes the current web application's context path.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What's the issue? Just put it there.
 
Bai Shen
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark E Hansen wrote:I think what you want to use is the <c:url> JSTL tag. Assuming your JavaScript is embedded in your JSP page, you should be able to just stick the tag into the JavaScript itself. For example, the following tag: will result in a URL to the image which includes the current web application's context path.



Ah, okay. I'll give that a try.

Bear Bibeault wrote:

What's the issue? Just put it there.


Umm, it gave me an error when I did that?

Weird. I just went back and tried it again and it didn't give me an error. I dunno what happened.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!