Monday, March 15, 2010

Add dynamic content using Expression Tags in JSP


Its same as in fairy tales, once upon a time there where static pages ruling the web. And now, everyone is wishing to have content to be present according to the situation. Everything is live now. Dynamic content is what everyone wishes to see.

JSP pages are one which allow one to embed Java code to HTML. This is where we take advantage in creating dynamic content.

Expression Tag 

You need to embed your Java expressions in between <%= and %>

whatever is given in between, it is evaluated at run time.

Following is an example program…



        <title>JSP 1. Expression Tags</title>



        <div align="center">

        <h3>Current Time:</h3>

        <%= new java.util.Date() %>  <br/>

        <h4>Refresh the page to update the time !!!</h4>





Above code displays current time as and when page is refreshed.

So, now just search for reasons where you need to have dynamic content, like content is dependent on the users previous actions and etc..,