by Dinesh Thakur Category: introduction to Servlet

All of us would have started programming in java with the famous "hello world" program. If you can recollect, we saved the file with a '.java' extension and later compiled the program using 'javac' and then executed the program using 'java'. Apart from introducing you to the language basics, the important point is that it is a client-side program. That means you write, compile and execute the program in the client machine (i.e., your PC). No doubt, it is the easiest and fastest way to write, compile and execute the program. However, it has little practical significance when it comes to real-world programming.



 
by Dinesh Thakur Category: introduction to Servlet

Important terms used in web application are discussed here.

 
by Dinesh Thakur Category: introduction to Servlet

Of these, HTTP servlets have some additional objects that provide session-tracking capabilities, the servlet writer can use the HttpSession interface to maintain the state of a client between client requests upto some time period. The capability of maintaining cookies is also provided by the HTTP servlets, The servlet writer uses the Cookie class to save small bits of information within the client machine, which can be retrieved at request processing time, Program illustrates the use of the HttpServlets.



 
by Dinesh Thakur Category: introduction to Servlet

A web resource application is a combination of static as well as dynamic web resource programs, images, etc. A static web resource resides in server and is executed in client side web browser, e.g., HTML. A dynamic web resource program resides in server, is executed in context of server and gives response back to the client, e.g., servlet, JSP. In web application, static web resource takes data from client side and takes it to the dynamic web resource as per request. The dynamic web resource processes the data and sends the response back to client in the form of response.



 
by Dinesh Thakur Category: introduction to Servlet

1. Servlet container loads our servlet class from WEB-INF\classes folder of deployed web application.

2. Servlet container instantiates (object creation) our servlet class object as Class.forName (“FolderName”).newInstance (); 



 
by Dinesh Thakur Category: introduction to Servlet

* Every software and non-software objects life cycle (considering all the operations that are taken place from object birth to object death)

 
by Dinesh Thakur Category: introduction to Servlet

* Response status code indicates the status of generated response to display on the browser window.

* Every generated http response contains one http status code, default status code is 200.

* If web resource program generates warnings based web page then the status code is 100-199.   

* If web resource program generates successful web page then the status code is 200-299.

* If request given to one web site is forwarded to another web site then the status code will be 300-399.

* If our web resource program is incomplete or invalid to process the request then the status code will be 400-499.

* If server fails to execute our web application the status code will be 500-599.     

* 400-599 are error status codes, Using them the programmer can debug the problems related       to web application execution and server.

* 100-399 indicates success response status codes that means they display web pages on browser window having output content. So these status codes will not appear on the web pages.

* For related information on http response status codes refer page no 49 and 50.      

* Response headers provide instructions to browser window through web server towards displaying web pages on the browser window.

* The content type we have placed in PW.println statements becomes response body http response.



 
by Dinesh Thakur Category: introduction to Servlet

The three important resources of servlet API.

1. javax.servlet.Servlet

2. javax.servlet.GenericServlet      (Abstract class)

3. javax.servlet.http.httpServlet    (Abstract class)



 
by Dinesh Thakur Category: introduction to Servlet

Process based Server Side Technology

• The procedure of transferring control from one process to another process or from one thread to another thread is called as the scheduling based control jumping or context switching.

 
by Dinesh Thakur Category: introduction to Servlet

Apache Tomcat is a Open source java based web server software. At present tomcat 7.0 is compatible with jdk1.6/1.7. Tomcat default port no is 8080(changeable).To download tomcat we use www.apache.org.



 
by Dinesh Thakur Category: introduction to Servlet

• Once web server is started one daemon process will be started to listen to clients continuously and to trap and take the client generated Http request.

• The process that runs continuously is called as daemon process.

 
by Dinesh Thakur Category: introduction to Servlet

• Listens to client request continuously (HTTP Request).

• Traps and takes client generated HTTP Request.

• Passes the HTTP request to an appropriate web resource program of web application (deployed web application).

 
by Dinesh Thakur Category: introduction to Servlet

Both are send input values to target web resource program like servlet program along with the request. The difference are



 
by Dinesh Thakur Category: introduction to Servlet

• The text that allows non-sequential access through hyper link is called as “hyper text”.

• Protocol http defines set of rules that are required to pass hyper text between browser to server and server to browser.

 
by Dinesh Thakur Category: introduction to Servlet

When four requests are given to a Servlet program.

a) The Servlet container creates one object of that Servlet class.

b) Servlet container starts 4 threads on that object representing 4 requests on per request basis.

 
by Dinesh Thakur Category: introduction to Servlet

In Java, Servlet container (also known as aWeb container) generates dynamic web pages. So servlet container is the essential part of the web server that interacts with the java servlets. Servlet Container communicates between client Browsers and the servlets.



 
by Dinesh Thakur Category: introduction to Servlet

Java Servlet life cycle consists of a series of events that begins when the Servlet container loads Servlet, and ends when the container is closed down Servlet. A servlet container is the part of a web server or an application server that controls a Servlet by managing its life cycle. Basically there are three phases of the life cycle.



 
by Dinesh Thakur Category: introduction to Servlet

There is a possibility of developing ‘n’ types of servlets, like httpservlet, ftpservlet, smtpservlet etc. for all these protocol specific servlet classes GenericServlet is the common super class containing common properties and logics. So, GenericServlet is not a separate type of servlet.



 
by Dinesh Thakur Category: introduction to Servlet

Server side web technology is used to develop dynamic web resource programs that having the capability to generate dynamic web pages. Server side web technologies are two types.

 
by Dinesh Thakur Category: introduction to Servlet

Client side programs can be written using different client side technologies. These are given to develop client side web resources such as html (Web), JavaScript (Netscape), VBScript (Microsoft), AJAX (asynchronous JavaScript and xml) programming languages.

 

Page 1 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.