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:
<PARAM NAME="Name" VALUE="Value">
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
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