JSP - Expression Language(EL)
Expression Language(EL) का इस्तेमाल JavaBean और implicit objects से content को प्राप्त करने के लिए किया जाता है |
Expression Language पर Arithmetic, Logical और Relational Operators या इससे सम्बंधित कुछ reserved words का इस्तेमाल किया जा सकता है |
Syntax for Expression Language(EL) in JSP
${expression}
Operators and Reserved Words in Expression Language
Operator में जो parenthesis(()) में दिए है वो reserved words है |
Operator | Description | Operator | Description |
---|---|---|---|
+ | Addition | ==(eq) | Equal to |
- | Subtraction | !=(ne) | Not Equal to |
* | Multiplication | &&(and) | Logical AND |
/(div) | Division | ||(or) | Logical OR |
%(mod) | Modullus | !(not) | Not |
<(lt) | Less than | empty | Empty Values |
>(gt) | Greater than | . | Accessing Bean Property |
<=(le) | Less than or Equal to | [] | Accessing Array Elements |
>=(ge) | Greater than or Equal to | () | for Subexpression |
Example for Expression Language in JSP
Source Code :${4 < 2} <br /><%-- false --%> ${2 < 4} <br /><%-- true --%> ${2 + 4} <br /><%-- 6 --%> ${2 - 4} <br /><%-- -2 --%> ${2 == 4} <br /><%-- false --%> ${2 lt 4} <br /><%-- true --%> ${2 gt 4} <br /><%-- false --%>
implicit Object in Expression Language(EL) in JSP
implicit Object | Description |
---|---|
pageScope | page scope(default scope) पर set किये गए attribute name से उसकी value को प्राप्त करने के लिए इस्तेमाल किया जाता है | |
requestScope | request scope पर set किये गए attribute name से उसकी value को प्राप्त करने के लिए इस्तेमाल किया जाता है | |
responseScope | response scope पर set किये गए attribute name से उसकी value को प्राप्त करने के लिए इस्तेमाल किया जाता है | |
sessionScope | session scope पर set किये गए attribute name से उसकी value को प्राप्त करने के लिए इस्तेमाल किया जाता है | |
applicationScope | application scope पर set किये गए attribute name से उसकी value को प्राप्त करने के लिए इस्तेमाल किया जाता है | |
pageContext | pageContext Object का वर्णन करता है | |
cookie | cookie object को प्राप्त किया जाता है | |
param | request parameter को प्राप्त किया जाता है | |
paramValues | request parameters को array में प्राप्त किया जाता है | |
header | HTTP request headers को प्राप्त किया जाता है | |
headerValues | सभी HTTP request headers को array में प्राप्त किया जाता है | |
Example for param implicit Object in Expression Language(EL) in JSP
<form action="print.jsp"> <input type="text" name="myname" /> <input type="submit" value="Submit" /> </form>print.jsp
Name : ${param.myname}
Example for requestScope implicit Object in Expression Language(EL) in JSP
<% request.setAttribute("myname", "UD"); %> Name : ${requestScope.myname}Output :
Name : UD
Example for sessionScope implicit Object in Expression Language(EL) in JSP
index.jsp<% session.setAttribute("myname", "UD"); %> <a href="print.jsp">Click Me</a>print.jsp
Name : ${sessionScope.myname}Output :
Name : UD