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.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)