Techno World Inc - The Best Technical Encyclopedia Online!

THE TECHNO CLUB [ TECHNOWORLDINC.COM ] => ASP .NET => Topic started by: Mark David on March 16, 2007, 02:00:27 PM



Title: Basic JSP scripting elements
Post by: Mark David on March 16, 2007, 02:00:27 PM
Basic JSP scripting elements

JavaServer Pages (JPSs) offer a number of ways to inject Java code into the Servlet code generated when a JSP is compiled.

Scriptlet code elements put the included Java code into the _jspService method. The included code needs to be complete java code (remember the trailing semicolons):

Code:
exciting HTML code 
<% String important = new String("Very important programmer"); %>
more HTML code

Expressions are evaluated and placed into out.print() methods to be written to the output stream. The code included is an expression, not a complete Java statement, so leave off the trailing semicolon:

Code:
HTML tags 
<%= important %>
HTML tags
<%= new java.util.Date() %>

Declaration elements insert the enclosed code into the body of the servlet code allowing the declaration of variables or methods:

Code:
HTML stuff 
<%!  private int counter = 0; %>