Home : Tutorials : JSP Tutorial


Syntax For Java Server Pages

Most of the HTML part, can be created using any standard WYSIWYG page editor. The only time you would want to use these Tags , would most probably be when you want to have Text Displayed Dynamically every time.  That's when you can use these tags and directly display the values in a particular variable etc.

JSP tags use the form <jsp:tag>, a form taken from XML. Some tags (particularly scripting tags) have a shortcut for use in HTML files, generally starting with <% and ending with %>. 

Note that these shortcuts are not valid for XML files.

Empty elements, tag constructs that have nothing between the start and end tags, can be shortened to one tag ending with />, as in this example: 

<!-- include tag with no body: -->
<jsp:include page="/portal/header.jsp"></jsp:include>

<!-- include tag can also be written like this: -->
<jsp:include page="/portal/header.jsp" /> 

White space is not usually significant, although you should make sure to put a space character between the opening tag and any attributes. For example: <%= myExpression %> is valid, <%=myExpression %> is not.


JSP Comments

A JSP comment is contained within <%-- and --%>, and can contain anything except the text --%>. The following example, therefore is incorrect: 

<%-- anything but a closing --%> ... --%> 

An alternative way to place a comment in a JSP is to use a Java comment. For example:

<% /** this is a comment ... **/ %> 


Generating Comments in Output to Client
In order to generate comments that appear in the response output stream to the requesting client, use the HTML and XML comment syntax as in the following example:

<!-- comments ... --> 

These comments are treated as uninterpreted template text by the JSP engine. If the generated comment is to have dynamic data, this can be obtained through an expression syntax, as in the following example: 

<!-- comments <%= expression %> more comments ... -->

Home  Previous  Next


Home : Tutorials : JSP Tutorial

 

Copyright© 1998-2004 All Rights Reserved. No portion of this site may be reproduced or redistributed without prior written permission from VistaEdge Technologies

All registered trademarks appearing on this site are the property of their respective owners. Java is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries. This site is not connected to Sun Microsystems, Inc. and is not sponsored by Sun Microsystems, Inc.