by Dinesh Thakur Category: Servlet with MySql Database

In order to see the data from the table the most common type of SQL statement executed in most database environments is the query, or SELECT statement. Select statements retrieval requests data from tables in a database. You can issue a simple SELECT statement that is designed to retrieve all data from the table.



 
by Dinesh Thakur Category: Session And Cookies

One of the ways to keep track of session between the client and the server is through the use of cookies. A cookie is a piece of information that a web server sends to the browser.



 
by Dinesh Thakur Category: Session And Cookies

HTTP is a stateless protocol; each time a client requests for a page, a separate connection is established between the client and the server. Thus, it provides no way for a server to maintain information for a particular user across multiple requests. There are many web applications where it is required to maintain this information. For example, in case of shopping cart, it is required to keep track of the list of items that are added in each user's cart. For this, the server must provide a way to store data for each client and distinguish clients from one another.



 
by Dinesh Thakur Category: Session And Cookies

In a web server, a session is a collection of all the requests made by a client (browser). HTTP is a stateless protocol. Between requests, it does not maintain any state of the client (browser). Suppose the client makes request for a web page, it should be checked whether the request is from an authorized user. It is impossible to check the authorization for each web page. It is necessary to maintain some information of the user while a user navigates between web pages. Thus, it is useful to maintain the state of client. The following processes arc used to maintain the state of a client:



 
by Dinesh Thakur Category: Session And Cookies

Usually the following four steps are followed while using sessions in servlets.

1. Accessing the Session object associated with the current request: In this step, invoke the getSession () method of the HttpServletRequest to return the HttpSession object.

 
by Dinesh Thakur Category: Session And Cookies

Cookies enable you to store the session information on the client side which has the following advantages,



 
by Dinesh Thakur Category: Session And Cookies

In order to read cookies that come back from the client (browser) in request header, you need to call getCookies () method of the HttpServletRequest. If the request contains no cookies this method returns null.

 
by Dinesh Thakur Category: Session And Cookies

Sending cookies to the client involves the following steps,

1. Create a Cookie object.

2. Setting the maximum age.

3. Placing the Cookie into the HTTP response headers.

 
by Dinesh Thakur Category: Session And Cookies

The Hypertext Transfer Protocol (HTTP) is the network protocol that the web servers and the client browsers use to communicate with each other. The HTTP is a stateless protocol. A client browser opens a connection and requests for a resource from the web server. The web server then responds with a requested resource and closes the connection.



 
by Dinesh Thakur Category: Servlet Chaining

This method sends a temporary redirect response to the client using the mentioned redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading ‘/’ the container interprets it as relative to the current request URL. If the location is relative with a leading ‘/’ the container interprets it as relative to the servlet container root.



 
by Dinesh Thakur Category: Servlet Chaining

This method forwards a request from a servlet to another resource (servlet, JSP file or HTML file) on the server. It enables one servlet to do prelude processing of a request and another resource to create the response.



 
by Dinesh Thakur Category: Servlet Chaining

This method of RequestDispatcher interface includes the content of web resource (servlets, JSP and HTML file) in the response. In other words, this method allows server-side to include the response of destination program to source program. Here ServletResponse object are passed as the argument of include () method.

 
by Dinesh Thakur Category: Servlet Chaining

In the diagram Below, Srvl program forwards the request to Srv2 only when the generated square value is less than 100,otherwise, the Srvl directly sends response to browser window displaying that square value.

 
by Dinesh Thakur Category: Servlet Chaining

The request object based RequestDispatcher object expects that the source servlet Program, destination web resource program and the destination web resource program be in the same web application.



 
by Dinesh Thakur Category: Servlet Chaining

GETREQUESTDISPATCHER ()

lnvokable on both request, servletContext object. Expects URL pattern of destination JSP or HTML programs as argument value. Generated RequestDispatcher object can point the destination servlet JSP program and HTML program.



 
by Dinesh Thakur Category: Servlet Chaining

While building a complex web application there might be a need to distribute the request to multiple servlets. This is where request dispatching comes into use. Due to this requirement Servlet container supports request dispatching within the same context.

 
by Dinesh Thakur Category: Servlet Chaining

• In any mode of servlet chaining, all servlet programs/web resource programs use the same request and response objects. If srvI, srv2, srv3 and srv4 servlet programs are in forwarding request mode of servlet chaining, the html output of srv1, srv and srv3 is discarded and only the output of srv4 servlet program goes to the browser window.



 
by Dinesh Thakur Category: Servlet Chaining

Taking a request from a browser window and processing it by using multiple servlets as a chain is called Servlet Chaining. In servlet chaining, communication occurs between servlet chains and servlet programs to process the request given by a client.



 

Page 12 of 12



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.