Can javascript use el expression?

WBOY
Release: 2022-04-13 18:41:10
Original
3103 people have browsed it

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.

Can javascript use el expression?

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

Can javascript use el expressions?

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>
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template