Marielle Lapidario Marielle Lapidario - 2 months ago 10
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:

$(document).ready(
function () {
var count = 0;
var lastCodeIGA = ${sessionScope.codeIGA}; // syntax error here
console.log(lastCodeIGA);
.
.
.
etc


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

Answer

You can use following to retrieve the required value.

var lastCodeIGA =  '${codeIGA}';
Comments