DEV Community

Cover image for What is servlet?
priyanshu pardhi
priyanshu pardhi

Posted on

1

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)

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay