0

I have this code in my jsp file :

div id="fullBG" style="width:1200px;background-repeat:  no-repeat ;">

 $("#fullBG").css("background-image", "url(" + bgImageUrl + ")");

I want to change the second line of code to java code.

How can I do this ?

Thanks.

xrcwrn
  • 5,339
  • 17
  • 68
  • 129

2 Answers2

0

You should avoid using scriptlets in JSP. Here is wonderfuly answer How to avoid Java Code in JSP-Files?.

If you find difficulty in writing EL, point us where are you facing the difficulty,

Community
  • 1
  • 1
Ramesh PVK
  • 15,200
  • 2
  • 46
  • 50
0

As I undestood you need dynamically change your background image. And you need to do it from java (jsp). If you need to do it one while page loading you can put background image to request attributes in servlet:

request.setAttribute("bgImageUrl", "your_url");

And in jsp:

$("#fullBG").css("background-image", "url(${bgImageUrl})");

If you need to do it without page reload: use ajax.

alexey28
  • 5,170
  • 1
  • 20
  • 25