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
.
Look below:
1 |
|
- Line
8
, We simplesly have set an atributesecretMessage
onrequest
- Line
9
, Weforward
thatrequest/response
to our view nammingsecret-message.jsp
1 |
|
- This method only
insert
at elementsecret-message
thecontent
of one variablesecretMessage
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's
code only inJSP
fileJavascript's
code inJS
file- We don’t need use
var
, limit the scope usinglet
!
- We don’t need use
Why doing simple things appear so difficult?
xoff.