Print a Spring variable in browser using JavaScript -


i trying print variable in if condition. it's done using spring , javascript. don't know spring. how print value of spring variable in browser?

   <!doctype html> <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script> <script> $(document).ready(function(){   $("p").click(function(){     $(this).hide();   }); }); </script> </head> <body> <p>if click on me, disappear.</p> <p>click me away!</p> <p>click me too!</p> </body> </html> 

i'll attempting piece comments on question answer, since seem have solved it.

what should first understand difference between server-side code parsing , execution (a jsp page you), , client-side code parsing , execution (html , javascript you). can read brief overview in top-rated answers this programmers.stackexchange.com question. further reading can found on wikipedia's articles on server-side scripting , client-side scripting. key concept take away client-side scripting article server-side scripts is:

[server-side scripts] produce output in format understandable web browsers (usually html), sent user's computer. user cannot see script's source code (unless author publishes code separately), , may not aware script executed. documents produced server-side scripts may, in turn, contain client-side scripts.

in terms of setup, means when request jsp page via browser, browser tells server hosting jsp page browser wants page. server executes jsp page produce document purely html , javascript in nature (perhaps css too, if wrote way) sending browser. the browser never sees jsp code. time server done parsing , executing jsp page, instances of ${someexpression} (jsp el statements) , other jsp-specific expressions (such taglibs, <spring:xx> tags) resolved client-side equivalent. basic jsp el statments (${...}), these resolve string value. if happen cleverly place el statement in javascript in jsp, such console.log("${myvariable}");, dynamically producing javascript code depend on output of el statement (in example, resolve console.log("myvariable-value");).

up point, server has been executing jsp code (and otherwise leaving html/js/css in page intact). no javascript has been parsed or executed. final "rendered" page, after server done executing jsp stuff, sent purely html/js/css client browser, receives , parses/executes it. @ point, browser sees console.log("myvariable-value");, without knowing or caring jsp code produced it, , executes (since cleverly placed el statement produce valid js).

this long-winded explanation means can following:


server-side jsp:

alert("${createbehavior.behaviorrevisionallowed}"); 

resulting code sent server client browser:

alert("false"); 

result after code executed in browser: alert box pops value false in it.


server-side jsp:

console.log("${createbehavior.behaviorrevisionallowed}"); 

resulting code sent server client browser:

console.log("false"); 

result after code executed in browser: value false logged console.


server-side jsp

return [$('#some-id'), "<spring:message code='bh-ms-0070'/>"]; 

resulting code sent server client browser:

return [$('#some-id'), "some-spring-message-string"]; 

result after code executed in browser: array in javascript return statement created value "some-spring-message-string" second element.


from question in comment "el variable", when said "el variable" meant fact el statement, such ${somestatement}, statement simple variable name, such ${createbehavior.behaviorrevisionallowed}. el statement see variable name in it, attempt find variable , value, , replace ${createbehavior.behaviorrevisionallowed} actual value.

let me know if further explanation needed.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -