Showing posts with label Servlet. Show all posts
Showing posts with label Servlet. Show all posts

Tuesday, 29 October 2013

Different ways of creating a Servlet

Create Servlet

Hello, friends here we will learn about how to create servlet.
  1. Every servlet class is either directly or indirectly implemented from Servlet interface given by servlet API.
  2. For programmer convenience, servlet API as provided the same abstract base classes for creating servlet.
  3. While developing web applications, a programmer can create a servlet class, by using any one of the following three approaches.
  • By directly implementing our class from the servlet interface.
Public class myserv implements Servlet
{
}
  • By extending our servlet class from a base class called GenericServlet.
Public class myserv extends GenericServlet
{
}
  • By extending our servlet class from a base class called HttpServlet.
Public class myserv extends HttpServlet
{
}

Monday, 28 October 2013

CGI and Servlet

Http Protocol

Protocols works at two levels
  1. System level
  2. Application level
System level protocols will communicate the data between IP addresses. For example, TCP/IP or UDP (user Datagram protocol).
  • Application level protocols works on top of system level protocols. This application level protocol communicates from one application to other.
  • For example, http is an application level protocol which communicates a browser and a server application.
  • http protocol is also a stateless protocol. It means http protocol doesn’t remember a client data from one request to another request.
  • http protocol has multiple methods to transfer a request from a browser to a server but only two methods are important called get and post.
  • In some cases, get method will be use and some time post method will be used to send the request from a browser to a server.

Difference between CGI and Servlet technology

CGI and Servlet
NOTE: Even though the no. of clients are increasing, if an application performance is not decreased then such type of application is called scalable application.

What is the difference between Process model and Thread model?

In process model, for each request a new process begins at OS level but in thread model for each request a new thread begins server process begins. So process model increases burden on the server and thread model reduced burden on the server.

Monday, 7 October 2013

Directory Structure

Servlet Directory Structure


Hello friends; Hitesh is here today I will show you how to create servlet directory structure.
  • While creating web applications, we should follow the standard directory structure, provided by the sum microsystem.
  • Sun microsystem has given this directory structure to make a web application as server independent. A web application principle is to write once deploy anywhere (WODA).
  • According to the directory structure, an application contains a root folder with any name.
  • Under root folder, a subfolder is required with the name “WEB-INF”.
  • Under “WEB-INF” two subfolder are required classes and lib.
directory structure

  • In “WEB-INF” folder put web.xml files.
  • In classes folder put all the .class files.
  • In lib folder put ojdbc14.jar.
  • In root folder we put jsp, .gif (images), all html files.

Sunday, 6 October 2013

MVC Architecture


In real time application in the case of server side programming one must follow the architecture to develop a distributed application.

To develop any distributed application, it is always recommended to follow either 3-tier architecture or 2-tier architecture.

3-tier architecture is also known as MVC architecture. M stand for Model (database programming), V stand for view (client side programming, HTML/AWT/APPLET/Swing/JSP) and C stand for controller (server side programming, Servlet).

The General Architecture of MVC or 3-tier:



mvc architecture

















  1. Client makes a request.
  2. Server side program receives the request.
  3. The server looks for or search for the appropriate resource in the resource pool.
  4. If the resource is not available server side program displays a user friendly message (page connot be displayed ). If the resource is available, that program will execute gives its result to server, server interns gives response to that client who makes a request.
  5. When server want to deals with database to retrieve the data, server side program sends a request to the appropriate database.
  6. Database server receives the server request and executes that request.
  7. The database server sends the result back to server side program for further processing.
  8. The server side program is always gives response to ‘n’ number of client concurrently.

Saturday, 5 October 2013

Web Container

  • A web container is a predefined application provided by a server, it takes care of the dynamic resource of a web application.
  • In a java based web applications, servlets and JSP’s are dynamic resources and the runtime support for then at the server will be provided by the container.
  • It consoles based java applications a class that contains main method acts as a container for other classes.

For Example:


Class service

{

Void withdraw()

{

---------

---------

}

Void deposite()

{

---------

----------
}
}
Class M
{
Public static void main(String args[])
{
Service s=new service();
s.withdraw();
s.deposite();
}
}

Here M class is providing runtime support for service class so main class is called a container.
In GUI based applications a frame acts as a container for other awt component like button, textField, textArea etc.

web container



IP address

Benefits of Container

Life Cycle Management
  • Servlets and JSP’s are dynamic resources of a java based application. The servlets or JSP’s will run on a server and at server side, a container will take care about life and death of a servllet / JSP.
  • A container will instantiate, initialize, service and destroy of a servlet or JSP. It means life cycle will be managed by a container.


Communication support

If a servlet or jsp wants to communicate with a server than apart from its business logics, some communication logic like socket and streams programming is also required in a servlet / JSP.
Implementing business logic is a burden on a programmer. Adding communication logic on a servlet / JSP will increase more burden on programmers.
To reduce the burden, a container act as a mediator between a server and a server / JSP and provides communication between them.

Multithreading

  • A container creates a thread for each request, maintains the thread and finally destroys it
  • whenever its work is finished.
  • By creating a web application, a programmer is no need of writing threading related logic because of the container.

Security

  • Some servlet / JSP’s of a web application are not accessible for all users.
  • A programmer is not required to write security code in a servlet / JSP. A container will automatically provide security for a servlet / JSP. If a programmer is informed to the container.

Tuesday, 1 October 2013

Why Web Applications

Why web applications?

The kind of application we can develop using java SE are

1. Stand-alone application
2. Distributed application

Stand-alone application are two types

1. Console application (GUI)
2. Desktop application (GUI)

Stand-alone application can provide service to one client at a time.
  1. To provide service to more clients, client/server model is introduced. This type of application in java are called distributed applications.
  2. In java socket programming is introduced (java networking) to create distributed application in java.
  3. In socket programming, client application is installed in multiple systems across network, to connect with a server application.
  4. In socket programming some problems are identified
  5. Client application is need to be installed at each client system. To take with a server.
  6. If a server location is changed then each client application is need to be modified separately.
  7. To run the client application client software is also need to be installed at client side.
To overcome the above problem, we got web applications.
In case of web application, we have the following advantages.

  1. No need to install client application of client-side just browser is enough.
  2. Even though a server location is changed but a client system can connect with the server.
  3. No special software is required at client-side.
Finally web applications will provide service more number of clients across internet.

What is web application?

  1. A web application is a server side application that runs on a server and provides services to client across the globe.
  2. A web application is a server and produces web pages onto a browser.

What a web Application contains?

A web application contains two types of resources

1. Static or passive resources
2. Dynamic or active resource.

  1. Passive resource are the files which always run on a browser.
  2. Active resource are those files which always run on a server.
For example: on html page is a passive resource, which runs on a browser. A server is an active resource, which runs on a server.

  1. A web application, which comprises only static resource are called static or presentation-oriented web application.
  2. A web application, which comprises both static and dynamic or only dynamic resource are called dynamic or service-oriented web application.



  1. For example : online tutorial contains only static resource. So it is a static web application.
  2. For example: gmail.com is a web application, which provides service like mailing and charting. So it is a dynamic web application.
  3. To create a dynamic web application both client side and server side technologies are used but to create a static web application only client side technologies are used.
  4. Client side technologies ate html, css, java script.
  5. Server side technologies are servlet, JSP, ASP, PHP, Cold fusion etc.
  6. A dynamic web application creation and execution need following
  7. A browser to send a request
  8. A client and server side technologies to create a web application.
  9. A serve to host a web application.
  10. A database for storing / reading data.