Thursday, February 17, 2011

Add Dynamic Content to your JSP page

As in the previous post, I showed that any HTML file can easily be turned into a JSP file i.e. by changing the file's extension to .jsp. So what is it that makes JSP useful that a simple html page? It is its ability to embed java code inside of JSP page. Following example shows how.
<HTML>
<BODY>
Hello World! The time is: <%= new java.util.Date() %>
</BODY>
</HTML>
Save the above file with .jsp extension. Now load it multiple times. You will see that every time you reload the page, it shows the current time.
We have already learned about java expressions <%= and %>
So that is what which makes JSP useful i.e. generating dynamic content that will change itself according to the client's request.

No comments:

Post a Comment

Please comment, if you like the post, you find any mistake or if you have any query.