Java Server Pages - Features

January 2017



Implementation of JSP code in the HTML page


A JSP file is a file with the .jsp extension containing HTML and specific tags:
  • <servlet> tags to integrate a servlet within the HTML code.
  • JSP syntax tags (there are four different types).

Through the use of tags, JSP can easily integrate Java code within the HTML code. The main advantage of this mechanism compared to servlets, is the separation between the data (directly encoded in HTML) and the logic (process) provided by Java.
JSP can be used to access reusable components (servlets, JavaBeans, Enterprise JavaBeans (EJB)).

The <servlet> tag


The first method for integrating Java content in an HTML page is to use the <servlet> tag.

The syntax is as follows:

<SERVLET NAME="name_of_servlet"  

 CODE="name_of_class"  

 CODEBASE="URL"  

 INITPARM="value"  

>  

<PARAM NAME="Name" VALUE="Value">  

</SERVLET>

Elements of a JSP page


A JSP page can contain four types elements (excluding the HTML code):
  • directives: comprehensive information on the page
  • statements: to declare methods and attributes
  • scriptlets: Java code that will be translated into code in the service() method
  • expressions: to easily send dynamically created string to the browser

JSP comments


With JSP you can add comments in two ways.
  • generate a comment visible in the HTML source code (HTML comment) of the client with the following syntax:

<!-- comments [<%= expression %>] -->
  • create a comment in the JSP code for the purpose of documentation (not visible to the client) with the following syntax:

<%-- comments --%>


Original document published on CommentcaMarche.net

Related


Published by deri58. Latest update on March 3, 2013 at 07:29 AM by deri58.
This document, titled "Java Server Pages - Features," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).