2 Minutes To Code (β Version)

JSP - 2 minute tutorial

JSP Expressions

Let's move over plain html code and learn our first concept provided by jsp spec an dit goes by the name "jsp expression".

Jsp expressions are basically any java expression placed inside and ; . What the web server does when it encounters a jsp expression is, it evaluates the java expression and places it as text in the webpage.

Using jsp expression

<html>
	<body>
		Hi friends<br>	
		Current server time is <%= new java.util.Date() %>
	</body>
</html>


jsp expression in xml format

Jsp spec allows to write all tags in a jsp in xml format. So, there is an alternate way to write jsp expression as shown below.
<html>
	<body>
		Hi friends<br>	
		Current server time is <jsp:expression > new java.util.Date() </jsp:expression>
	</body>
</html>

Corresponding webpage

This is how the above jsp expression code will get rendered in a webpage :



Notice that unlike in the first.jsp page example where every time the exact same date is displayed in the webpage, when using jsp expression, the date changes every time as the java code used to generate it new java.util.Date() is evaluated every time to get the value.