Introduction to Servlet

Click to rate this post!
[Total: 0 Average: 0]

Introduction to Servlet:

Servlet innovation is utilized to make web application (dwells at server side and produces dynamic website page). Servlet innovation is powerful and versatile due to java dialect. Before Servlet, CGI (Common Gateway Interface) scripting dialect was well known as a server-side programming dialect. In any case, there was many disservices of this innovation. We have examined these hindrances underneath. There are various interfaces and classes in the servlet API, for instance, HttpServlet ,Servlet, GenericServlet, ServletResponse ,ServletRequest,.

What is Servlet?

Servlet can be portrayed from numerous points of view, contingent upon the unique circumstance. Servlet is an innovation i.e. used to make web application. Servlet is an API that gives numerous interfaces and classes including documentations. Servlet is an interface that must be executed for making any servlet. Servlet is a class that broadens the capacities of the servers and react to the approaching solicitation. It can react to solicitations. Servlet is a web segment that is sent on the server to make dynamic website page.

MVC Architecture :

MVC Architecture

Servlet web over view:

A web application is an application open from the web. A web application is made out of web parts like Servlet, JSP, Filter and so on and different segments, for example, HTML. The web segments normally execute in Web Server and react to HTTP ask.

CGI(Commmon Gateway Interface)

CGI innovation empowers the web server to call an outside program and pass HTTP ask for data to the outer program to prepare the demand. For each demand, it begins another procedure.

Hindrances of CGI

There are numerous issues in CGI innovation:

  • On the off chance that number of customers builds, it sets aside more opportunity for sending reaction.
  • For each demand, it begins a procedure and Web server is constrained to begin forms.
  • It utilizes stage subordinate dialect e.g. C, C++, Perl.
  • Preferred standpoint of Servlet

Advantage of Servlet:

There are many points of interest of servlet over CGI. The web holder makes strings for dealing with the various solicitations to the servlet. Strings have a ton of advantages over the Processes, for example, they share a typical memory range, and lightweight, cost of correspondence between the strings are low. The essential advantages of servlet are as per the following:

Better execution: since it makes a string for each demand not prepare.

Performance: on the grounds that it utilizes java dialect.

Robust: Servlets are overseen by JVM so we don’t have to stress over memory spill.

Secure: light of the fact that it utilizes java dialect.

Servlet API :

The javax.servlet and javax.servlet.http bundles speak to interfaces and classes for servlet programming interface.

  • The javax.servlet bundle contains numerous interfaces and classes that are utilized by the servlet or web holder. These are not particular to any convention.
  • The javax.servlet.http bundle contains interfaces and classes that are in charge of http ask for as it were.
  • We should perceive what are the interfaces of javax.servlet bundle.

Interfaces in javax.servlet package

  1. Servlet
  2. ServletRequest
  3. ServletResponse
  4. RequestDispatcher
  5. ServletConfig
  6. ServletContext
  7. SingleThreadModel
  8. Filter
  9. FilterConfig
  10. FilterChain
  11. ServletRequestListener
  12. ServletRequestAttributeListener
  13. ServletContextListener
  14. ServletContextAttributeListener

JAVA Tutorial Video

Classes in javax.servlet package

  1. GenericServlet
  2. ServletInputStream
  3. ServletOutputStream
  4. ServletRequestWrapper
  5. ServletResponseWrapper
  6. ServletRequestEvent
  7. ServletContextEvent
  8. ServletRequestAttributeEvent
  9. ServletContextAttributeEvent
  10. ServletException
  11. UnavailableException

Interfaces in javax.servlet.http package

  1. HttpServletRequest
  2. HttpServletResponse
  3. HttpSession
  4. HttpSessionListener
  5. HttpSessionAttributeListener
  6. HttpSessionBindingListener
  7. HttpSessionActivationListener
  8. HttpSessionContext (deprecated now)

Classes in javax.servlet.http package

  1. HttpServlet
  2. Cookie
  3. HttpServletRequestWrapper
  4. HttpServletResponseWrapper
  5. HttpSessionEvent
  6. HttpSessionBindingEvent
  7. HttpUtils (deprecated now)

HttpServlet:

The Http Servlet  grows the GenericServlet and execute Serializable interface. It results the http particular frameworks.

Methods of HttpServlet class

  1. public void service(ServletRequest req,ServletResponse res)
  2.  protected void service(HttpServletRequest req, HttpServletResponse res
  3. protected void doGet(HttpServletRequest req, HttpServletResponse res)
  4. protected void doPost(HttpServletRequest req, HttpServletResponse res)
  5. protected void doHead(HttpServletRequest req, HttpServletResponse res
  6. protected void doOptions(HttpServletRequest req, HttpServletResponse res)
  7. protected void doPut(HttpServletRequest req, HttpServletResponse res)
  8. protected void doTrace(HttpServletRequest req, HttpServletResponse res)
  9. protected void doDelete(HttpServletRequest req, HttpServletResponse res)  protected long getLastModified(HttpServletRequest req)

Life Cycle of a Servlet:

The Life cycle of the servlet is maintained by the web container

  1. The class of Servlet is loaded.
  2. Servlet instance is created.
  3.  The init method is invoked.
  4. The service method is invoked.
  5. The destroy method is invoked.Servlet Life Cycle

    As showed in the above graph, there are three conditions of a servlet: new, prepared and end. The servlet is in new state if servlet example is made. Subsequent to conjuring the init() technique, Servlet comes in the prepared state. In the prepared state, servlet plays out every one of the undertakings. At the point when the web compartment conjures the annihilate() technique, it movements to the end state.

 

Subscribe
to our newsletter

Drop Us A Query

Trending Courses
  • Microsoft Azure Architect Technologies(AZ-300) | ITGuru
    Microsoft Azure Architect Technologies(AZ-300)
  • Azure is a great Microsoft Cloud Computing platform in providing various cloud services through online. ITGuru Certified Azure Architect certification course gives you the practical knowledge on Azure Cloud platform through real-world use cases from live experts

  • ServiceNow Admin Training | ITGuru
    ServiceNow Admin Training
  • Getting knowledge of cloud platforms like ServiceNow is essential in today’s world for the smooth running of projects in cloud platform. Turn your dream to the reality of becoming the Certified ServiceNow Administrator through ServiceNow Administration online certification Course with practical examples by live industry experts through online at ITGuru with real-world use cases.

  • Workday Financials Training | ITGuru
    Workday Financials Training
  • knowing the basics on any platform like Workday is not enough to sustain the IT industry. Hence it is essential to go beyond on Workday basics like Workday Financials training which lets you know the application of Financials management in real -world use cases from ITGuru Live Experts in a practical way.

  • Workday Training
  • An organization is considered as the best one when it offers the best benefits to the employee. Moreover, the greater the employee benefits, the greater the contribution to the organization. ITGuru let you know the practical workday Human Resource Management(HRM) features with live examples by experts

  • Python Online Course | ITGuru
    Python Online Course
  • Turn your dream into reality by ITGuru live experts with real-world use cases through practical knowledge on python online course and become the certified associate in python programming and become a master in python programming

  • Python Programming | ITGuru
    Python Programming
  • Python is the trending programming language in the IT industry. Mastering in python programming gives you more value among the people in the IT industry. Hence start today to learn python programming online by live experts with real-time uses cases at ITGuru


100% Secure Payments. All major credit & debit cards accepted.

Call Now Button