Javascript can use el expressions. Method: 1. The JavaScript code directly uses EL expressions in the JSP page, and the syntax is "$(function(){new ...("${param.alert}");}); 2. Use advance Use the form to define JS variables.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
EL (Expression Language) is to make JSP easier to write. Expression language is inspired by ECMAScript and XPath expression language. It provides methods to simplify expressions in JSP, making JSP code more simplified.
How to use el expression in JavaScript.
1. The JavaScript code is in the JSP page, which can use EL expressions directly. For example:
<script type="text/javascript"> $(function () { new BacklogOverview("${param.alert}"); }); </script>
2. The JS code is a separate .js file, which can be imported into the JSP At this time, it can be solved by defining JS variables in advance, such as:
<c:set var="contextPath" value="${pageContext.request.contextPath}" scope="application"/> <script> <%--JS gloable varilible--%> var contextPath = "${contextPath}"; </script>
EL syntax
Accessing model objects in JSP is through EL expressions grammatical expression. The format of all EL expressions is represented by "${}". For example, ${userinfo} represents getting the value of the variable userinfo.
When the variable in the EL expression is not given a scope, it will be searched in the page scope by default, and then in the request, session, and application scope in sequence. You can also use scope as a prefix to indicate which scope the variable belongs to. For example: ${pageScope.userinfo} means accessing the userinfo variable in the page scope.
【Related recommendations: javascript video tutorial, web front-end】
The above is the detailed content of Can javascript use el expression?. For more information, please follow other related articles on the PHP Chinese website!