Is it possible to write javascript with Java in a jsp -
If I had a code like this, can I run it without problems? I think JavaScript will run before javascript, so there will be no problem in JavaScript, but I have not done this before:
This is a very bad programming style, but yes, it is possible.
The code I'm working on now has done some very similar things. I think you really want to:
& lt; Script type = "text / javascript" & gt; & Lt;% = functThatOutputsJavascript ()% & gt; & Lt; / Script & gt;
And in fact, you can make worse by using Java Conditions to modify JavaScript output:
& lt; Script type = "text / javascript" & gt; While (i> gt;) {{if (servervor)) {%> Console.log ("The server says yes!"); & Lt;%} Other {%> Console.log ("The server says!"); & Lt;%}% & gt; } & Lt; / Script & gt;
If the server server is correct, then it will output to this code:
& lt; Script type = "text / javascript" & gt; While (i & gt; 0) {console.log ("The server says yes!"); } & Lt; / Script & gt;
Or if this is incorrect, then this code:
& lt; Script type = "text / javascript" & gt; While (i & gt; 0) {console.log ("The server does not say anything!"); } & Lt; / Script & gt;
This is a terrible coding style, and I hope you will not do it in practice! If you are wondering how to avoid written code in this way, then check this question:
A general suggestion is to use JSP EL (JSP Expression Language) to make server-side variables with their Javascript , And then write all your logic in javascript
Comments
Post a Comment