SERVLET API (SERVLET (Java Servlets are programs that run on a Web or…
Java Servlets are programs that run on a Web or Application server and act as a middle layer between a request coming from a Web browser or other HTTP client and databases or applications on the HTTP server.
- Used to create web application(resides at server side and generates dynamic web page)
- Robust and scalable because of java language.
- Many disadvantages of this technology.
- Many interfaces and classes in the servlet API such as servlet, Generic Servlet, Http Servlet, Servlet Request, Servlet Response.
- Servlets can be described in many ways, depending on the context.
- Servlet is a technology example used to create web application.
- Servlet is an API that provides many interface and classes including documentations.
- Servlet is an interface that must be implemented.
- class that extend the capabilities of the servers and respond to the incoming request.
ADVANTAGES OF SERVLETS
- Servlets performance are better.
- execute within the address space of a web server
- Servlets are platform-independent because they are written in Java.
- The full functionality of the Java class libraries is available to servlet.
- Have security : enforces a set of restrictions to protect the resources on a server machine.
- Read the explicit data sent by the clients.
- Read the implicit HTTP request data sent by the clients.
- Process the data and generate the results.
- Send the explicit data to the clients.
- Send the implicit HTTP response to the client.
Request/response protocol which is based on client/server based architecture. In this web browser, search engines, etc behaves as a HTTP clients, and the Web server like servlet behaves as a server.
JSP VS SERVLETS
- JSP is look like standard HTML. Normally include HTML markup tags. HTML codes can be written easily. Used when content is mostly fixed-template data.
- Servlets is HTML codes have to be written to the PrintWriter or OutputStream. Used when small amount of content is fixed-template data.
CORE SERVLET API
- Generic Servlet
- Servlet Request
- Servlet Response
- Contains generic interfaces and classes that are implemented and extended by all servlets.
- service() method
- Accepts two arguments servlet Request object and Servket Response object.
- The rquest made by client while the response object is used to return a response back to the client.
ADVANTAGE OF GENERIC SERVLET
- Easier to write
- Has simple lifecycle methods.
- To write Generic Servlet you just need to extend and override the service()method.
- Encapsulates the client
- Allows the servlet access to Names of the parameters passed in by the client.
- The protocol being used by the client
- The names of the remote host that made the request and the server that received it.
- Subclasses of Servlet Request allow the servlet to retrieve more protocol-specific data.
- Encapsulates the server
- Gives the servlet methods for replying to the client.
- Allows the servlet to set the content length and MIME type of the reply.
- Provides an output Stream, ServletOutputStream through which the servlet can send the reply data.
- Subclasses of Servlet Response give the servlet more protocol- specific capabilities.