Você está na página 1de 47

A Seminar Training Report

On

Web Component Development


With Servlets & JSP Technologies
In partial fulfillment of requirements for the degree of

Bachelor of Technology In

Computer Science

Department of Computer Science

Submitted To: Mr. Yogesh Kumar (H.O.D)

Submitted By:Padmesh Soni CS/08/55

APEX INSTITUTE OF ENGINEERING & TECHNOLOGY, SITAPURA, JAIPUR RAJASTHAN TECHNICAL UNIVERSITY
2011

Acknowledgements

I take this opportunity to express my profound sense of gratitude and respect to all those who helped me throughout the duration of this project. I acknowledge the effort of those who have contributed significantly to my project. I express my sincere gratitude and thankfulness towards our H.O.D Er. Yogesh Kumar (AIET), for his valuable time and guidance.

I feel privileged to offer my sincere thanks and deep sense of gratitude to Mr. Arun Gupta at NIIT Pvt. Ltd. for expressing their confidence in me by letting me work on a project of this magnitude and using latest technologies and providing their support, help & encouragement in implementing this project.

I am grateful to all our friends for providing critical feedback & support whenever required. There are times in such projects when the clock beats you time & again & you run out of energy, you just want to finish it once & forever. Parents made us endure such times with their unfailing humour & warm wishes.

I regret any inadvertent omissions.

Padmesh Soni

PREFACE

In todays competitive world, computers have assumed critical importance in every field. It has become an essential qualification for almost all ventures. In my Bachelor degree Of Computer Science I have been prepared to be at part with the industrial requirements. So, the industrial training is a must and the project work undertaken during this training exhibits the practical as well as the theoretical knowledge of the student.

As part of my industrial training I undertook a project in Adv. JAVA, MY SQL at NIIT Private Limited, Jaipur. While doing this project I learned a lot and brushed up my earlier knowledge. This training has provided me an opportunity to have practical, which has increased my sphere of knowledge to a great extent. Now I am better equipped to handle the real things than anyone else who has not undergone any such training does.

During my stay here I learned how an actual Web Site progresses, what sort of problems actually occurs during the development of such websites.

LIST OF CONTENTS Contents Page No

Front page......................... 1

Acknowledgement....... 2

Preface........................... 3

List of Contents......... 4

Company Profile...... 6

Introduction to Web Application Technologies ..... 8

Developing a View Component ........ 15

Developing a Controller Component.. 19

Developing Dynamic Forms 21

Sharing Application Resources Using the Servlet Context .22

Designing the Business Tier 24

Developing Web Applications Using Struts 26

Developing Web Applications Using Session Management ... 29

Using Filters in Web Applications ... 34

Integrating Web Applications with Databases.......... 37

Developing JSP Pages........... 39

Introduction to Project 40

Interface Required. . 41

Snap Shots of Project.. 42

Bibliography 48

COMPANY PROFILE

Introduction: NIIT is a part of the HCL group which has a big presence in the Indian InfoTech industry. The Indian computer education industry is now worth around Rs. 6.5 bn. NIIT has pioneered the computer education business in India by creating a nation-wide network of training schools. There is a strong marketing focus with the company tapping uncharted overseas markets to expand the training business with the help of local business partners. Courses have been designed for special segments like computer illiterate mothers / senior citizens. NIIT has around 650 centers, out of which around 50 are owned. NIIT had a head-start of more than 2 years over Aptech. The management has a big emphasis on quality. All the aspects of NIITs business have ISO 9000 certifications. The company is now busy implementing Crosbys Complete Quality Management System at all its locations to provide high-quality, zero-defect service to all its customers. NIIT is the first company in India to adapt the Economic Value Added (EVA) concept as a measure of corporate performance. Around four hundred front-line managers at NIIT have been trained in EVA to extract maximum resource productivity at their respective business areas.

Major line of Business: It is one of the larger computer & software training organizations Select Products and Services: Computer Training: through franchises Software Services (Educational Multimedia): NIIT is the largest educational multimedia developer in the country. It started educational software development in 1991 with a contract for IBM and now has impressive clients in educational multimedia, namely AT & T - GIS, Chase Manhattan, IBM Thailand, NETG, Oracle, etc. Key Differentiating Factors: NIIT is one of the leading players in the computer training industry in India. NIIT has moved to be a developer of computer-based training tools and is now also a software services provider

Location:
Address: NIIT Pvt. Ltd. Vaishali Nagar Centre, Office No. 2,3 & 4, 3rd Floor, Unique Aspire Building, Cosmo Colony, Amrapali Marg, Viashali Nagar, Jaipur Rajasthan, India Phone No. 91-141- 4086300 E-mail. global@niit.com

1. Introduction to Web Application Technologies

Web Application Technologies:


The HTTP (Hyper Text Transfer Protocol) is similar to many other Internet protocols, for example SMTP and FTP because HTTP is a protocol to transfer data from the server to client. One fundamental difference between most other Internet protocols and HTTP is that the typical Internet protocol supports several requests per connection. HTTP supports only one request per connection. There is no need for the server to hold the connection open, therefore the server does not need to manage the connections state. HTTP was created in conjunction with the related HTML standard. HTML is a document display language that lets users link from one document to another. The combination of the HTTP protocol and the HTML page description language constitutes the foundational technologies of the World Wide Web. HTTP Client-Server Architecture:

Fig: HTTP Client-Server Architecture For every exchange over the web using HTTP, there is a request and a response. The web browser sends a single request to the server. The web server determines which file is being requested and sends the data in that file back as the response. The browser interprets the response and represents the content on the screen. 8

Web Site Structure: A web site is a collection of HTML pages and other media files that contains all the content that is visible to the user on a given web server.

The index.html file is a special file used when the user requests a Uniform Resource Locator (URL) that ends in a slash character (/). The web server presents the user with a directory listing for that URL unless an index.html file exists in that directory. If that is the case, then the web server sends the index.html file as the response to the original URL. Uniform Resource Locator: A URL is canonical name that locates a specific resource on the Internet. It consists of: protocol://host:port/path/file For example: http://www.soccer.org:80/league/Spring2001.html If the port no. is the standard port for the given protocol, then that no. can be ignored in the URL.

Java Platform, Enterprise Edition 5 (Java EE 5):


Java EE is the industry standard for developing portable, robust, scalable and secure server-side. Java technology applications. It is built on the solid foundation of Java Platform, Standard Edition (Java SE).

Execution of CGI Programs:


Early in the development of HTML, the designers created a mechanism to permit a user to invoke a program on the web server. This mechanism was called the Common Gateway Interface (CGI).When a web site includes CGI processing, this is called web application.

Fig: Running a Single Instance of a CGI Program

Fig: Running Multiple Instances of a CGI Program 10

Execution of Java Servlets:

Fig: Running a Single Instance of a Servlet

Fig: Running Multiple Instances of Servlet A Java servlet is a Java technology program that, similar to a CGI program, runs on the server. The types of tasks that you can run with servlets are similar to those you can run with CGI. However, the underlying executing architecture is different. The basic processing steps for Java servlets are quite similar to the steps for CGI. However, the servlet runs as a thread in the web container instead of in a separate OS process. The web container itself is an OS process, but it runs as a service and is available continuously.

Java Servlets:
Servlets run within the Java EE component container architecture. This container is called the web container is a Java Virtual Machine (JVM) tool interface that supplies an implementation of the servlet API. Servlet instances are components that are managed by the web container to respond to HTTP requests.

11

Fig: Web Server Architecture with JAVA Servlets

Java Server Pages Technology:


JSP pages are just one way of implementing the concept of HTML pages with embedded code, or template pages. Three examples of other popular technologies available for creating HTML with embedded code are PHP, ASP and Ruby on Rails. JSP pages are converted by the web container into a servlet instance. That servlet then processes each request to that JSP page

Fig: Processing of JSP page

12

Web Application-Three-Tier Architecture:

Model-View-Controller (MVC) Architecture in a Web Application:

Three-tier architecture and MVC architecture are not the same. They are not even related concepts. Three-tier architecture and MVC architecture are completely separate (orthogonal) concepts. Even the topology of each is different: three-tier is a linear (layered) architecture; Model-View-Controller is triangular. A fundamental concept of three-tier architecture is that all communication passes through the middle ware tier. In MVC architecture the controller communicates with the model (and in some implementation with the view also), and the view obtains its date directory from the model.

13

Model 2 Architecture:

y y

Fig: Deployment Diagram of a web container using Model 2 architecture A Servlet acts as the controller, which verifies form data, updates the model with the form data, and selects the next view as the response. A JSP page acts as the view. This renders the HTML response, retrieving data from the model necessary to generate the response, and provides HTML forms to permit user interaction. Java technology classes act as the model, which implements the business logic of the web application.

Web Application Migration:

Fig: Application Design Matrix


14

2. Developing a View Component


There are four fundamental types of views: y Data Presentation This includes any data presented on visible screen. There are many forms of presentation including graphs, spreadsheets, listings, and so on. y Data Forms Forms for data entry are also considered view components. y Navigational aids This type of view includes menus, hyperlink, site maps and so on. y Informational screens or pop-ups This type of view includes welcome text, instructions, help screen, error messages, confirmation dialogs and so on.

HTTP Revisited: HTTP GET Method:


A browser issues an HTTP GET request when: y The user selects a link in the current HTML page y The user enters a URL in the location field or the address field. HTTP Request:

15

Example Headers: Header Accept Host Referer Use The MIME types the client can receive The internet host and port number of the resource being requested The address from which the RequestUniversal Resource Identifier (URI) was obtained The information about the client originating the request

User-Agent

HTTP Response:

16

Example Headers: Header ContentType ContentLength Server CacheControl Use A MIME type (such as text/html) which classifies the type of data in the response The length (in bytes) of the payload of the response An informational string about the server that responded to this HTTP request A directive for the web browser (or proxies) to indicate whether or not the content of the response should be cached

Request & Response Headers:

17

Sequence Diagram of an HTTP GET Request:

Configuring a Servlet Definition:

18

3. Developing a Controller Servlet

HTTP GET & POST Methods:

Developing a Controller Servlet:

19

Servlet API Retrieve Form Parameter:

20

4. Developing Dynamic Forms


Servlet Life Cycle:

The ServletConfig API:

Note: It is used when developing a user detail in online submission forms like as registrations.

21

5. Sharing Application Resources Using the Servlet Context


Servlet Context:
y y y A web application is a self contained collection of static and dynamic resources. The web application deployment descriptor is used to specify the structure and services used by a web application. The Servlet Context object is the runtime representation of the web application.

Servlet Context API:

Web Application Life Cycle:

y When the web container is started, each web application is initialized. y When the web container is shut down, each web application is destroyed. y A Servlet Context listener can be used to receive these web application life cycle events.

22

The Servlet Context Listener API:

23

6. Designing the Business Tier


Describing the Analysis Model: y An analysis model is used to bridge the gap between use case analysis and component
design. y An analysis model consists of three abstract component types:

Component Boundary

Symbol

Description Communicates between the user and the system. Provides a services-oriented layer between boundary and entity components. Represents domain objects and persistent data.

Service

Entity

Designing a Service Component:


Service components add a service layer between boundary and entity components. This section describes two fundamentals types of services: entity-related services & facades.

Entity Service:
Some entity-related operations cannot be performed by the entity component itself: y Creation- Creating a new instance of the entity. y Retrieval- Retrieving a unique instance in the data store. y Selection- Retrieving a set of instances in the data store. y Aggregation- Performing a calculation (such as an average) over a set of instances. y Deletion- Removing an instance from the data store.

24

Faade Service: y A Faade service might be used to reduce coupling between boundary components and
other services:

High Coupling

Low Coupling

25

7. Developing Web Applications Using Struts


Struts Framework:
Struts is an open source framework that is a subproject of the Jakarta project under the Apache Software Foundation. The Struts framework also satisfies the MVC pattern by using so called action classes to implement the controller components. A Struts application use only one infrastructure servlet, called the ActionServlet.

Front Controller Pattern:


The Front Controller pattern solves two major problems: 1. Decouple view and controller components You have separated the code of your views and controllers, but the controller servlets still need to know the URL path to the view component. Struts introduces a level of indirection in which the view is specified by a symbolic name that is mapped to the view path in the Struts configuration file. 2. Abstract any common infrastructure processing from the application-specific controllers.

Struts MVC Framework:


Framework provides following elements: y Infrastructure servlet controller y Base classes y Configuration files Why use a framework like Struts: y Provides flexible, extensible infrastructure for MVC y Lets you focus on what is important to your application, such as:  Application Controllers  Model Components  views

Struts Activity Diagram:

26

Struts Action Class:

27

You need to do following: y y y y Configuring the Struts infrastructure controller. Configure a servlet mapping for struts controller. Configure the action mappings. Install the struts library files.

28

8. Developing Web Applications Using Session Management


HTTP and Session Management:
HTTP is a stateless protocol. Each request and response message connection is independent of all others. This is significant because from one request to another (from the same user) the HTTP server does not maintain a reference to the previous request. Therefore, the web container must create a mechanism to store session information for a particular user.

The web container can keep a session object for each user:

Designing Web Applications to Use Session Management:


The session management module can be design with three main steps: 1. Design multiple, interacting views for a use case. 2. Create a Struts action application controller for each activity in the use case. 3. Create a unique Struts URL for each activity in the use case.

Using Session Management in a Web Application:


Using Session Management: y Each activity-specific action must store attributes (name/object pairs) that are used by other requests within the session. y Any action can access any attributes that has already been set by processing a previous request. y At the end of session, the action might destroy the session object.

29

Session API:

Storing Session Attributes:


Only one session object is created for a given client within a single web application. However, several use cases in the same web application can share the session object. Therefore, you should create attribute names that avoid ambiguity within the complete web application.

Accessing Session Attributes:


Anyone can use the getAttribute() method to retrieve data in the session object.

Destroying the Session:

30

Using Cookies for Session Management:


y y y y y Cookies are sent in a response from the web server. Cookies are stored on the client s computer. Cookies are stored in a partition assigned to the web server s domain name. Cookies can be further partitioned by a path within the domain. All Cookies for that domain (and path) are sent in every request to that web server. Cookies have a lifespan and are flushed by the client browser at the end of that lifespan.

Cookies API:

Performing Session Management Using Cookies:

Fig: Web Container Session ID Cookie Storage 31

Fig: Web Container Session ID Cookie Retrieval

Using URL-Rewriting for Session Management:

Fig: URL-Rewriting Session Management

32

URL-Rewriting Implications:
y y y y URL-rewriting is used when cookies cannot be used. The server appends extra data on the end of each URL. The server associates that identifier with data it has stored about that session. With this URL: o http://host/path/file;jsessionid=123 session information is jsessionid=123.

Every HTML page that participates in a session (using URL-rewriting) must include the session ID in all URLs in those pages. This requires dynamic generation. Use the encodeURL method on the response object to guarantee that the URLs include the session ID information.

33

9. Using Filters in Web Applications


Web Container Request Cycle:
y y y Request processing by the web container Applying filters to an incoming request Applying filters to a dispatched request

Web Container Request Processing: y Request and response objects are created for each incoming request.

Fig: Request and Response Applying Filters to Incoming Request: y A filter intercepts the request before it gets to the requested resource. y A response is returned to the client through the filter.

34

Filters can be used for many activities in a web application, such as: o Blocking access to a resource based on user identity or role membership o Auditing incoming requests o Compressing the response data stream o Transforming the response o Measuring and logging servlet performance

Filters applied to a Dispatch: y Filters can be applied to an internal dispatch, such as a request forward or include.

Filters API:

35

y y

The init method is called once when the filter instance is first created. Use the init method to: o Perform one-time initialization of resources the filter uses over its lifetime o Retrieve the initialization parameters configured in the deployment descriptor

y y

The doFilter method is the filter equivalent of a servlets service method. As a developer, you implement the doFilter method to do the following: o Perform the operations you want to occur every time the filter is invoked. o Decide whether to pass the request to the next component in the filter chain or halt the request entirely. To pass on the request, call the doFilter method on the FilterChain reference. y y The destroy method is the last method called in the life cycle of a filter instance. Use the destroy method to clean up any resources allocated in the init method.

Configuring the Filter:


y Typically, filters are applied to requests from a client. You can specify the dispatcher element in a filter mapping. This determines what type (or types) of requests invoke the filter. Valid values are: o REQUEST The filter is applied if the request is from a client. o INCLUDE The filter is applied if the request is from a request dispatcher include. o FORWARD The filter is applied if the request is from a request dispatcher forward. o ERROR The filter is applied if the request is a result of an error condition.

36

10. Integrating Web Applications with Databases

Designing a Web Application:


Design the domain objects of your application. Design the database tables that map to the domain objects. Design the business services (the model) to separate the database code into classes using the data access object (DAO) pattern.

Data Access Object (DAO) Pattern:


The data access object (DAO) pattern separates the business logic from the data access (data storage) logic. The data access implementation (usually JDBC technology calls) is encapsulated in DAO classes. The DAO pattern permits the business logic and the data access logic to change independently. For example, if the DB schema changes, then you would only need to change the DAO methods, and not the business services or the domain objects.

JDBC API:
The JDBCTM API is the Java technology API for interacting with a relational DBMS. The JDBC API includes interfaces that manage connections to the DBMS, statements to perform operations, and result sets that encapsulate the result of retrieval operations. Techniques are described for designing and developing a web application, in which the JDBC technology code is encapsulated using the DAO design pattern. An incorrect technique is to create a connection object for each request, but this approach is extremely slow and does not scale well. 37

Traditional Approaches to a Database Connection:


y y y y Use DriverManager.getConnection to create database connections with every request. Create a connection and store it as a member variable of the servlet. Use a connection pool to recycle connections. Can use servlet context to store the connection pool: o A custom connection pool might present maintenance problems. o Servlet context is not available to business tier components (such as DAOs). Java EE application servers provide a namespace, which can be accessed using JNDI APIs. Java EE application servers must support storing DataSource resources in JNDI namespace. DataSource is an object which encapsulates the information to connect to the database: o Database URL o Driver o User name and password Most servers provide a database connection pool that is accessed using the DataSource.

y y y

DataSource API:

38

11. Developing JSP Pages Java Server Pages Technology:


JSP pages are just one way of implementing the concept of HTML pages with embedded code, or template pages. Three examples of other popular technologies available for creating HTML with embedded code are PHP, ASP and Ruby on Rails. JSP pages are converted by the web container into a servlet instance. That servlet then processes each request to that JSP page

Steps of JSP Processing:

Processing of JSP:

39

12. Introduction to Project

Overview:
DVD Library Management is a report of recent occurrences, information of DVDs that has lately taken type. DVD Library Management is the management of DVDs which is presented by admin these are Padmesh and Jack with additional users. The world is changing at a very fast rate and so as they ways to access different medium. This project pattern has only three features which are describe by me the whole 11 modules of this report. In my summer training period I have done a course in J2EE and worked on a simple project of a DVD Library Management website. DVD Library Management is a module of simple three features in which admin and additional users are add their DVDs according to genre and show them with their preferences of title, year, genre. Purpose The purpose of my project is only that from this I can understand the processing of Servlets with their additional features.

40

Interface Required

Platform Used : Language Used: Database Used : Software Used : -

Window XP HTML, J2EE (Servlets) MY SQL Netbeans 7, Glassfish and Apache Servers.

Hardware Requirements:

Processor Ram

::-

456 MHz Or Above 1 GB And Above

TOOLS:

Front-End

:-

J2EE

Back-End

:-

MY SQL

41

Modules of the Project & Their Description


The Project has number of modules, which perform specified task. Following are the name and description of the modules of the project. Authentication Required : This Module Accepts the user name and searches in the data-directory if the information is valid then programs continue otherwise programs access by the admin authentication. Home: This module have 4 parts these are Display my DVD Library, Add a new DVD, Set User Pref and last one is Home also. Display DVDs: Add DVD: This module is used for display all DVDs. This module is used for add a new DVD in the file of DVDs. Preferences: This module is used for select the preferences of DVDs to show them. Success: This module is used for show that DVD has been added successfully. Add DVD Form: Set Preferences: This module is used for add DVD form. This module is used for html form of preferences.

42

Snapshots of the Project

Fig: LoginFilter Authentication

43

Fig: Home Page

Fig: Add DVD Page


44

Fig: Set User Preferences Page

Fig: Success Page


45

Fig: List Shown Page

Fig: Error Shown Page


46

Bibliography

www.google.com www.w3schools.com www.java.com http://struts.apache.org/

47

Você também pode gostar