Dynamic contents and expressions

Dynamic contents and expressions

In the previous section we saw how any HTML file can be turned into a JSP file by changing its extension to .jsp.  Of course, what makes JSP useful is the ability to embed Java.  Put the following text in a file with .jsp extension (let us call it hello.jsp), place it in your JSP directory, and view it in a browser.
<HTML>
<BODY>
Hello!  The time is now <%= new java.util.Date() %>
</BODY>
</HTML>

Notice that each time you reload the page in the browser, it comes up with the current time.
The character sequences <%= and %> enclose Java expressions, which are evaluated at run time.

This is what makes it possible to use JSP to generate dyamic HTML pages that change in response to user actions or vary from user to user.

Exercise:  Write a JSP to output the values returned by System.getProperty for various system properties such as java.version, java.home, os.name, user.name, user.home, user.dir etc.


Leave a comment

0 Comments.

Leave a Reply

  • Read this materials also:
  • Scriptlets
  • First JSP
  • JSP Declarations
  • JSP Tags
  • JSP Sessions
  • Working with Scriptlets and HTML
  • JSP Directives
  • JSP server
  • JSP Interview Questions-3
  • What is JSP ( Java Server Pages )
  • Sitemap   Follow j2eetutorial on Twitter    

    Δ Top