Expression tag ( <%= %>)
- This tag is used to sent the output of the expression to the output stream like method println().
- This tag allows the developer to embed any Java expression and is short for out.println().
- This tag starts with <%= and ends with %>.
- A semicolon ( ; ) does not appear at the end of the code inside the tag.
<HEAD>
<TITLE>MCA</TITLE>
</HEAD>
<BODY>
Date : <%= new java.util.Date() %>
</BODY>
</HTML>
Declaration tag ( <%! %> )
- This tag allows the developer to declare variables or methods.
- Before the declaration you must have <%!
- At the end of the declaration, the developer must have %>
- Code placed in this tag must end in a semicolon ( ; ).
- Declarations do not generate output so are used with JSP expressions or scriptlets.
<HEAD>
<TITLE>MCA</TITLE>
</HEAD>
<BODY>
I am pursuing <%=course%>
</BODY>
</HTML>
Scriptlet tag ( <% ... %> )
- Between <% and %> tags,any valid Java code is called a Scriptlet. This code can access any variable or bean declared.
- Any code in scriptlet is executed when user asks to jsp page.
- Executing logic at server side
- Implementing conditional HTML by posing a conditional on the execution of portion of page.
- Printing HTML portion repeatedly by placing them into JSP Scriptlet’s Loop
<HEAD>
<TITLE>MCA</TITLE>
</HEAD>
<BODY>
<%
for(int i=0;i<5;i++){
%>
<br>This is jsp demo</br>
<%
}
%>
</BODY>
</HTML>
OUTPUT of this JSP page is
This is jsp demo
This is jsp demo
This is jsp demo
This is jsp demo
This is jsp demo
Directive tag ( <%@ directive ... %>)
- A JSP directive gives special information about the page to the JSP Engine.
- There are three main types of directives:
- page - processing information for this page.
- Include - files to be included.
- Tag library - tag library to be used in this page.
Comments