Expressions-JSP
Aug 10, 2016
Make sure to subscribe to our newsletter and be the first to know the news.
Aug 10, 2016
Make sure to subscribe to our newsletter and be the first to know the news.
-JSP expression automatically print out whatever is being sent between the tags.
-Expressions are evaluated and output is sent to the browser.
-Expressions are later resolved and consumed by HTML itself.
<%= expression %>[Anything which comes on right hand side int i=1;
int z=x+y;
Date dt =new Date();
Point To REMEMBER:
NO semi-colon at the end.
Ease of using Expressions.
Without expression:
<%@ page import="java.util.* %>
<html>
<body>
Date: <% out.println(new Date());%>
</body>
</html>
With expression:
<%@ page import="java.util.*" %>
<html>
<body>
Today's Date:<%=new Date() %>
</body>
</html>
-Whenever container encounters expression, Container takes everything typed between the <%= %> and put it as an argument in out.println() <%= new Date() %>Becomes
out.println(new Date());
Tip for Students:
You people always by mistake put up a semi-colon at the end which result in
<%= new Date(); %>
Becomes
out.println(new Date(););
Which becomes error then.
Hence,No semi-colon(;) at the end of Expression.
FirstJSP.jsp
<%@ page import="java.util.*" %>
<html>
<body>
<%@ include file="Header.html" %>
<b>
<Hello User!!!Welcome to the world of JSP !!
</b>
Current Date : <%= new Date() % >
<%@ include file="Footer.html" %>
</body>
</html>