1

I have a controller which returns a ModelAndView object

return new ModelAndView("operatorDetail", model);

I can then access the elements in the model object from my JSP page like this

<c:if test="${not empty operator and operator.regionId eq item.regionId}"

my question is, is there a way I can access those elements in my javascript code ?. I thought about putting those values in an input element in HTML and make it hidden and access their values, but is there a more practical way?

thank you.

Md. Rejaul Karim
  • 115
  • 1
  • 1
  • 10
Jalil.Jarjanazy
  • 839
  • 1
  • 9
  • 22

1 Answers1

0

Yes of course you can have something like this. Declare var in jsp

<c:set var="yourJspVar" scope="session" value=" your object"/>

and in java-script set variable like

<script>
  var jsVar = '${yourJspVar}';
  alert(jsVar);
</script>
manikant gautam
  • 3,521
  • 1
  • 17
  • 27