A Servlet is a Java class that runs within a web container in an application server, servicing multiple client requests concurrently forwarded through the server and the web container. The web browser establishes a socket connection to the host server in the URL , and sends the HTTP request. Servlets can forward requests to other servers and servle...

Read More

The Web container is responsible for managing the servlet’s life cycle. The following figure is explaining the life cycle of a Servlet. The Web container creates an instance of the Servlet and then the container calls the init() method. At the completion of the init() method the Servlet is in ready state to service requests from clients. The contai...

Read More

HttpSession provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user. The servlet container uses this interface to create a session between an HTTP client and an HTTP server. The session persists for a specified time period, across more than one connection or page request fr...

Read More

This is a commonly asked interview question. The “http protocol” is a stateless request/response based protocol.  But consider a situation where you need to store certain information across requests like when a User logs into your website, not matter on which web page he visits after logging in, his credentials will be with the server, until he log...

Read More

A Cookie is a piece of text that a Web server can store on a user’s hard disk. Cookies allow a website to store information on a user’s machine and later retrieve it. These pieces of information are stored as name-value pairs. The cookie data moves in the following manner: If you type the URL of a website into your browser, your browser sends the r...

Read More

Weshould use doGet() when you want to intercept on HTTP GET requests. You should use doPost() when you want to intercept on HTTP POST requests. That's all. Do not port the one to the other or vice versa (such as in Netbeans' unfortunate auto-generated processRequest() method). This makes no utter sense. GET Usually, HTTP GET requests are idempotent...

Read More

 You should have doGet call doPost, or vice versa.   protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { ServletOutputStream out = resp.getOutputStream(); out.setContentType(“text/html”); out.println("

Output to Browser

"); out.println("Writt...

Read More

ServletConfig of in javax.servlet.*;  package is implemented by the servlet container to initialize a single servlet using init(). That is, you can pass initialization parameters to the servlet using the web.xml deployment descriptor. For understanding, this is similar to a constructor in a java class. ServletConfig object is created one for each s...

Read More

RequestDispatcher defines an object that receives requests from the client and sends them to any resource (such as a servlet, HTML file, or JSP file) on the server. The servlet container creates the RequestDispatcher object, which is used as a wrapper around a server resource located at a particular path or given by a particular name. This interfac...

Read More

In this post we have already read how to use forward() and include() There is a little difference between calling the forward() and include() method. The forward() method intended for use in forwarding the request, meaning after the response of the calling servlet has been committed. You cannot merge response output using this method. The include()...

Read More

Redirect request is used to redirect resources to different servers or domains. This transfer of control task is delegated to the browser by the container. That is, the redirect sends a header back to the browser / client. This header contains the resource url to be redirected by the browser. Then the browser initiates a new request to the given ur...

Read More

Generating Web Project From Maven Template: You can create java web application using maven-archetype template in command line which is Windows box and terminal which is prominent amoung linux and mac community. Before proceeding navigate to the folder in which you want to create project so that its easy to keep track of activities. tuturself ad...

Read More

In this series of creating web appliction in java in the previous post we create we application using Spring. In this tutorial we will walk through the basic of Java we appliction which are servlets and JSP. This is the basic concept which all other high level frameworks use internally. Generating Web Project From Maven Template: pwd /home/tutur...

Read More

In traditional Servlet model, 1 Request is processed by 1 Thread. The Servlet container handles each request by spawning a new thread / by picking up an available thread for each request from the Web container’s thread pool. In this model the Servlet container can only handle new requests as long as it has free threads in this pool. As long as your...

Read More

FOLLOW US ON LinkedIn



Explore Tutu'rself