Fundamental Concepts of Servlet Technology - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

Fundamental Concepts of Servlet Technology

Share This



Once you have got the initial understanding of Web Application Development, now you must be ready to take on Servlets.

Servlet is a Java-based technology that lets you write robust and scalable Dynamic Web Applications. In Servlet Technology, you need to develop Servlets and upload them into the server. The users will access those servlets via HTTP and will get the result back.


Servlets are nothing but writing Java classes which has the capability of running within and exploiting the server environment. It has to be accessed within the remote server by a user client.

So, you as a developer will write some servlets and will put those servlets in the server, Client users will access those servlets via HTTP through user request. 

When the user request reaches the server, depending on the type of the request, as the server already knows which servlet to load, it loads a particular servlet, it might work alone or it might communicate with other servlets and ultimately generates a result. 

This result is sent back (by the server) as a response to the request back to the client.

So in a nutshell, if you want to develop a dynamic web application, you need to write servlets. Now the real question is whether is it a pure java class or not.

Generally speaking, servlets are pure java classes that extend an abstract class javax.servlet.http.HttpServlet , and you can start writing your codes like following
import javax.servlet.http.HttpServlet; public class MyServ extends HttpServlet { //further codes }
Here, MyServ is the name of the servlet and it extends an abstarct class HttpServlet , hence you need to manage your import accordingly. HttpServlet has two methods doGet() and doPost() that descends down in MyServ and hence your code should look like below

import javax.servlet.http.HttpServlet; public class MyServ extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) { } protected void doPost(HttpServletRequest request, HttpServletResponse response) { } }
As a developer, you need to override either of them depending on the nature of the client request that you as a developer have designed for the client. Don't worry about HttpRequest and HttpResponse for the time being. The abstract of the client's request and response respectively. So primarily this is a basic structure of a servlet.

We recommend the tutorial on Http to be checked out next so that you can learn Servlet in a better way.

In any case, if want to grasp deeper knowledge of Servlet internals, you can check out our tutorial on Servlet Anatomy 

Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.