Hello there,
I’m working with a project using JSP nowadays.
That project make uses of a lot of Javascripts calls.
I don't understand why people insists put on JSP: scriptlets, CSS and Javascript at the same page.
I, really, sure… I don't uderstand.
I going to show how we can use Java's variable and use it on Javascript method… at another file.
The Controller:
1 | |
Line 8, We simplesly have set an atribute secretMessage on request.
Line 9, We forward that request/response to our view namming secret-message.jsp.
The JS:
1 | |
This method only insert at element secret-message the content of one variable secretMessage.
The JSP:
1 | |
Line 6, we simplesly make the import of the script.js.
Line 10, it’s defined the place for show de message.
Line 13, at this point, we make the bind beetween Java’s variable and Javascript!
That allows us do what we need to do on right place:
Java'scode only inJSPfile.Javascript'scode inJSfile.- We don’t need use
var, limit the scope usinglet!


- We don’t need use
Why doing simple things appear so difficult?
xoff.