Some JSP tags

As part of jsp page we can use various elements.Template text that is placed as part of the jsp will be passed onto the client as it is. The code written between <% and %> is called scriptlet. In the below jsp page line one and last line tags are called as template text.
last line <br>
<%
for(int i=0; i<10; i++){
 System.out.println("Hi");
}
%>
<br> last line
<% start of the scriptlet
%> end of scriptlet
Whatever is added between <% and %> is called scriptlet and it is placed as it is in the service method. According to the jsp specification web container can support any language for implementing scriptlet. But most of the vendors are supporting only java language for implementing the scriptlets.
line one <br>
<%
System.out.println("Hi "+j);
%>
<br> last line
The above jsp file will be converted into a servlet by the jsp compiler as shown below:
public class first_ser extends ...{
 ...
 try{
 ...
 out.println("line one <br>");
 System.out.println("Hi "+j);
 out.println("<br> last line");
 ...
}
<%! int x = 100;
<%! indicates that it is a declarative statement. x will be declared as a instance variable of the servlet.

No comments:

Post a Comment