Posts Tagged ‘server’

Explain Different Types Of Tags In JSP Interview Asked Questions And Answers

Different Types Of Tags In JSP


Java Sever Page (JSP) is an abstraction for servlet in which we have less java code and more tags(HTML and JSP). A JSP page is basically used for views with dynamic data(unlike HTML) and evolved basically for people who do not know java and still work at j2ee server side programming.

Depending upon the type of the usage the tags in JSP page are categorized as :


  1. Scripting Tags
  2. Standard Action Tags
  3. Custom Tags

Scripting Tags : These tags are meant for compile time and translation.This means that these tags are meant for translation of code to the servlet. Different types of scripting tags are:

a. Directive Tag

b. Declarative Tag

c. Scriptlet Tag

d. Expression Tag


a. Directive Tag : There are three types of directive tags :

1.Page Directive : It is used for imports,encoding etc.

Example: <%@ page import=”…” %>

2.Include Directive : Its is used for static inclusion of JSP and HTML pages

Example: <%@ include file=”anotherJsp.jsp” %>

3.Tag lib Directive: It is used for including tag libraries

Example: <%@ taglib uri=”…” prefix = “..”%>

b. Declarative Tag : These tags are used to declare variables or methods for the servlet translated servlet class.

Example: <%! int i =0;%>


c. Scriptlet Tag : These tags are used to write java code inside the JSP page.What goes inside the scriptlet tag is merged into the service method of the translated servlet code.

Example: <% System.out.println(“Hello”);%>


d. Expression Tag : These tags are used to print expressions.What is written inside this tag goes as an argument for out.print() inside the service method of the translated servlet.

Example : <%= “Hello” %>


It should be noted that we do not use semicolon inside expression tag because it will go as an argument in ou.print() function,hence will result in syntax error.While in case of declarative tag and scirptlet tag we use semicolon.

Number of View :1348

Tags: , , , , , , , , , , ,

No Comments

Life Cycle Of A Servlet Explained Handling Servlet Life-Cycle Events Servlet Life Cycle Servlet Interview Questions Java Servlet Programming

Life Cycle Of A Servlet 

A servlet is a java code which runs at the server side to process request and return response to the client.

In other words, a servlet is an extension to the server which processes request and returns response as an HTML page to the client. Like applets we donot have main method in a servlet. As in case of applet,its life cycle is taken care by the browser itself,similarly in case of servlet its life cycle of a servlet is managed by the server/container.


Life Cycle Of A Servlet denotes the phases it goes through. These phases are symbolized by the life cycle methods in the servlet.As server manages the Life Cycle Of A Servlet, these life cycle methods are called by the server itself. Let us have a look at different Life Cycle methods Of A Servlet. These are as follows :


  1. init
  2. service
  3. destroy


1. init : The init method is the first Life Cycle method Of A Servlet. It is this method which after being called by the server makes a servlet eligible for being called a servlet. After the servlet class constructor is called,the init method is called by the server. The method looks like :

public void init(ServletConfig sc) throws ServletException {
  // Initialization code...


Here we can see that the ServletConfig object is passed to the init method. This object is created by serverand passed to the init method. Having received the ServletConfig object ,a servlet is said to be a servlet.

2. service : This life cycle method is called every time a request is sent to the servlet .This means that the servlet’s init method has been called and servlet is ready to process requests.This method looks like :

public void service(ServletRequest request,
                    ServletResponse response)
      throws ServletException, IOException{

3.destroy : This is the last phase in the Life Cycle Of A Servlet. Before the servlet object is garbage collected at the server side this method is called to relinquish the resources at the server side. This method looks like :

public void destroy() {
    // Finalization code...

It can be noted that the init method is called only once in the Life Cycle Of A Servlet, service is called as many times as many the requests are fired and destroy is called only once in the Life Cycle Of A Servlet.

Number of View :878

Tags: , , , , , , , , , ,

No Comments

Content Protected Using Blog Protector By: PcDrome.

Mahol Dot Org is Stephen Fry proof thanks to caching by WP Super Cache