Java server (Tomcat 9.0.48) Ignores ${} this expression [duplicate] - javascript

This question already has answers here:
${} template literal (ES2015) conflict with JSP EL syntax
(2 answers)
Closed 1 year ago.
I am relatively new to Java web-development and I'm trying to execute JavaScript code in a JSP file, i.e ${(format.date)}, but when I view the source code on my web-browser it completely ignores the expression ${}.
Any particular reason why the server is ignoring it? How do I overcome this?
<Script>
${(format.date)}
</Script>
FYI: format.date is just a random syntax but the server would still ignore anything that would be inside curly brackets.

The server ignore the syntax, because it doesn't find a variable in any scope.
<c:set var="pattern">MM/dd/YYYY</c:set>
<fmt:formatDate value="${format.date}" pattern="${pattern}"/>

Related

Symbol behind the .js [duplicate]

This question already has answers here:
Why pass parameters to CSS and JavaScript link files like src="../cnt.js?ver=4.0"?
(9 answers)
Closed 3 months ago.
What is "?_=3.5-SNAPSHOT-Dev" mean after ".js"? I do some research on google but no idea what it mean and what it use for
<script type="text/javascript" src="js/jquery-3.5.1.js?_=3.5-SNAPSHOT-Dev"></script>
It depends on the server that's serving your Javascript. Generally, variables like those on JS files are used for cache busting. I think in your example, 3.5-SNAPSHOT-Dev could be a release tag. If this JS file is now on your own machine, you can safely discard the ? and anything after that. If you're getting this from another server somewhere, seek out documentation about that server to see what they use the _ variable for.

Access python method from plain javascript [duplicate]

This question already has answers here:
Call Python function from JavaScript code
(6 answers)
Closed 3 years ago.
I have this python method shown below in a separate file and want to access and get value using plain js (no frame works used.) is there any way i can achieve this?
def myPythonCode :
....
...
return somevalue
You can use python wrapper for google V8 engine called PyV8
It act as a bridge between the Python and JavaScript objects, and support to hosting Google's v8 engine in a python script.

Colon after colon syntax while calling a function in Javascript [duplicate]

This question already has an answer here:
Colon after function declaration in javascript [duplicate]
(1 answer)
Closed 4 years ago.
I came across a syntax somewhere on the web recently and couldn't grasp its meaning.
What I understand is that when we write props: Object inside the brackets, it means we're assigning a default value to props as Object. But what does the 2nd colon signify? It looks like a key-value pair but is confusing me still.
Tried searching on the web but wasn't able to search due to lack of terminology. Any ideas what this means?
someFn(props: Object): Object {
return someOtherFn(props);
}
These are type annotations. They are not standard javascript. They are added when using tools that layer static typing onto javascript. The two most popular flavors are Typescript and Flow.
When you write code that uses this syntax you will transpile your source code into code that is syntactically valid for execution by running one of the above mentioned tools on your code. When you do, it will tell you if your usage of the types is correct, raise warnings that are helpful in development, and then strip all this out so it can actually be run.

How to avoid this javascript eval()? [duplicate]

This question already has answers here:
How to execute a JavaScript function when I have its name as a string
(36 answers)
Closed 7 years ago.
I'm trying to rid my code of a couple of evals that I have in my javascript, but I'm not sure of the best way to achieve what I'm trying to do.
I have a "filter form" on a bunch of my pages, with a bit of JS attached to it that reloads parts of the page depending on what the user does.
Different pages require different actions though.
So my solution (that I came up with yearrrrs ago...) was
<form name="callback_loadCalendar">
<form name="callback_loadNames">
Etc.
And this horrible bit of JS (attached to onchange events etc) to then call the relevant function:
if (f.getAttribute('name') && f.getAttribute('name').indexOf('callback') === 0)
eval(f.getAttribute('name').substr(9)+'()');
E.g. that would call loadCalendar() and loadNames() respectively.
What SHOULD I be doing instead?
Thanks!
If the functions are in the global scope, then you can use bracket notation in the global scope to access the function references.
window[f.getAttribute('name').substr(9)]();

What's the purpose of starting semi colon at beginning of JavaScript? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What does the leading semicolon in JavaScript libraries do?
I have noticed a lot of jQuery plugins start with
;(function(){ /* something in here */ })();
I just wondered what the beginning semi-colon was for, as well as the empty parentheses at the end.
The semi-colon is there in case you include this script just after some 'bad' script that doesn't properly close off its last line with a semi-colon. In this case it's possible the two scripts would be combined and result in invalid code. For example if you are merging multiple script into a single response.
The () at the end is executing the function. This is creating a closure. Private variables and methods can be declared within the scope of this function that cannot be accessed from outside the script.
This construct :
(function(){ /* something in here */ })()
Is used to create a new scope in Javascript.
More info on function scope here.
Regarding the semicolon, I never seen it before. I think it's a security for when you concatenate several scripts, since semicolons are optional in some cases at the end of the file.

Categories

Resources