Marielle Lapidario Marielle Lapidario - 1 year ago 61
Java Question

How to retrieve setAttribute from servlet into JavaScript

I'm trying to retrieve the value of my setAttribute into my javascript code but I get a syntax error when i run the page.

Here is the code of my setAttribute in my servlet:

request.setAttribute("codeIGA", codeIGA); //a string is being passed here

here is the code of my JS:

function () {
var count = 0;
var lastCodeIGA = ${sessionScope.codeIGA}; // syntax error here

How can retieve the value from my servlet and input it into my JS?

Answer Source

You can use following to retrieve the required value.

var lastCodeIGA =  '${codeIGA}';