In this section we will discuss about the elements of JSP.In this section we will discuss about the elements of JSP.
In this section we will discuss about the elements of JSP.
Structure of JSP Page :
JSPs are comprised of standard HTML tags and JSP tags. The structure of JavaServer pages are simple and easily handled by the servlet engine. In addition to HTML ,you can categorize JSPs as following -
A directives tag always appears at the top of your JSP file. It is global definition sent to the JSP engine. Directives contain special processing instructions for the web container. You can import packages, define error handling pages or the session information of the JSP page. Directives are defined by using <%@ and %> tags.
<%@ directive attribute="value" %>
This tag is used for defining the functions and variables to be used in the JSP. This element of JSPs contains the java variables and methods which you can call in expression block of JSP page. Declarations are defined by using <%! and %> tags. Whatever you declare within these tags will be visible to the rest of the page.
<%! declaration(s) %>
In this tag we can insert any amount of valid java code and these codes are placed in _jspService method by the JSP engine. Scriptlets can be used anywhere in the page. Scriptlets are defined by using <% and %> tags.
Comments help in understanding what is actually code doing. JSPs provides two types of comments for putting comment in your page. First type of comment is for output comment which is appeared in the output stream on the browser. It is written by using the <!-- and --> tags.
<!-- comment text -->
Second type of comment is not delivered to the browser. It is written by using the <%-- and --%> tags.
<%-- comment text --%>
Expressions in JSPs is used to output any data on the generated page. These data are automatically converted to string and printed on the output stream. It is an instruction to the web container for executing the code with in the expression and replace it with the resultant output content. For writing expression in JSP, you can use <%= and %> tags.
<%= expression %>