Turn Desktop View Off
by Dinesh Thakur

Servlets are platform independent and can work with almost all the web servers. They can be executed on any web server that supports the servlet API. Some of the web servers having built-in support for Java servlets are Tomcat server (Apache), Java web server (Sun Microsystems), Enterprise server (Netscape), Zeus web server (Zeus Technology), Tengah application server (Weblogic) and Sun web server (Sun Microsystems).



 
by Dinesh Thakur

Internet and WWW are often used interchangeably but both are different. Internet is the global network of computer networks whereas Web is one of the services provided over Internet. That is, Web is an application running over Internet. While creating web applications, the main goal is to perform most of the processing on the browser side, there by, reducing processing load on the server side.



 
by Dinesh Thakur

JSP is a tag-based language, i.e., code is written within specified tags. It is developed by Sun Microsystems. Unlike servlet program, we can write HTML tags within the JSP program, making it easier to build.



 
by Dinesh Thakur

Accessing data in a database or in any other data sources is a significant operation in web programming. Data access from JSPs and servlets is done through Java Database Connectivity (JDBC).



 
by Dinesh Thakur

HTML exhibits high performance by taking less time to load in the browser. However, when we use HTML page for important user details, by default, all the parameters that are passed appended in the URL. This compromises with the security. On the other hand, applet takes more time to load but there is no problem with Java security. This is an advantage of this technique.



 
by Dinesh Thakur

In doGet Method the parameters are appended to the URL and sent along with the information. Maximum size of data that can be sent using do Get it 240 bytes. Parameters are not encrypted. doGet method generally is used to query or to get some informationfromthe server.



 
by Dinesh Thakur

HttpServlet is an abstract class given under the servlet-api present. It is present in javax.servlet.http package and has no abstract methods. It extends GenericServlet class.



 
by Dinesh Thakur

HTTP headers are the request to a server for information and the resulting response. When you input an address into your browser, it sends a request to the server hosting the domain and the server responds. You can see the request and response using the basic HTTP Header Viewer. The HTTP Header Viewer can be used to view the Headers or Headers and Content of any valid http:/ / url. When the HEAD is selected, the request is for the server to only send header information. AGET selection requests both headers and file content just like a browser request. Information in response headers may include:



 
by Dinesh Thakur

The ServletRequest is a predefined interface present in javax.serviet package. The object of ServletRequest interface deals with the client request and fetches it to the servlet program. This object is created by the servlet container and is used as the argument of service method (life cycle method).



 
by Dinesh Thakur

The Servlet object is a Java object that is initiated and managed by the Servlet container. However, the Java object needs to be implemented descriptive to the Servlet container. The following rules are specified by the Java Servlet specification for implementing the Servlet object:



 
by Dinesh Thakur

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

Important terms used in web application are discussed here.

 
by Dinesh Thakur

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

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

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

* 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

* 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

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

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

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

• 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

• 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

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



 
by Dinesh Thakur

• 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

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

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

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

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

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

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.

 
by Dinesh Thakur

Before creating the first servlet, you need to understand the Servlet API and Tomcat Servlet container. The Servlet API provides interfaces and classes that are required to built servlets. These interfaces and classes are group into the following two packages :



 
by Dinesh Thakur

The Common Gateway Interface (CGI) is the first technology used to generate dynamic contents. It allows a web client to pass data to the application running on the web server so that a dynamic web page can be returned to the client according to the input data. For example, when you use a search engine, buy a book at an online store; get a stock quote etc., your browser uses CGI to communicate with a server side application.



 
by Dinesh Thakur

Java servlets provide web developers with a simple consistent mechanism for extending the functionality of a web server and provide dynamic behaviour for web applications. Servlets are Java classes that function like CGI programs. They accept a request from a client (usually a web browser), process that request and return a response to the client. All servlets are loaded and executed by a servlet container that can run by itself or as a component of a web server. The servlet container is also referred to as a servlet engine in the early days of servlet technology.



 
by Dinesh Thakur

• The logic and data of stand alone, desktop applications are specific to that computer where these applications are running.

• The logics and data of client-server applications, two-tier applications like JDBC applications are specific to one network where they are running. In the above said two-tier, client-server applications the server allows only known clients (recognized clients).