DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for What is servlet?
priyanshu pardhi
priyanshu pardhi

Posted on

What is servlet?

What is Servlet?

Imagine we have a client machine and a server. Client requests the server for a page (let's say). Now this page could be static, or it could be dynamic (built at runtime). When client requests the server, it will be like I don't have any page, so you have to build that web page at runtime, than the request goes to an helper application also know as Web Container, e.g. Tomcat, JBoss, Websphere, etc).

Web Container contains "Servlet", a java file which can take the request from client on the internet, process it and respond with a response as a HTML page. Servlet will convert the client request, fetch the values, process the information and return a HTML page.

Image description

Web Container also contains β€œDeployment Descriptor”,Β a simple XML document that is used to map URL to the servlet.

But how do you create a servlet?

A servlet is a normal java class which extends HttpServlet, since we want this servlet features ( request, process, response ) the response from servlet will be in HTML format (you can also send the response in JSON/XML format) now that HTML page will go from your server to client machine in the format of Response Object.

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.