4. Contents
SERVLETS
SERVLETS AND JSP
HOW SERVLETS WORKS?
• Servlet API
• Servlet Interface
• Servlet Life Cycle
• Cookies & Session
CREATING A SIMPLE SERVLET
JDBC
Conclusions
References
5. IntRoDUCtIon to oRGAnIZAtIon
A subsidiary of TATA CONSULTANCY SERVICES LIMITED
(TCS Ltd), one of the world’s leading information technology
consulting, services and business process outsourcing
organizations. CMC execute large and complex turnkey projects
and have built, managed and supported our customers IT
systems across the value chain infrastructure, applications and
business processes.
6. PRojeCt DesCRIPtIon
The purpose of this project is to:
The E-Music World application is an Online Website for an
Organization. It is a virtual showcase for different types of
products like FILM, GHAZHAL,POP, DEVOTIONAL , and
ROCK, CLASSICAL,FOLK etc.
8. PRojeCt PURPose
• The main aim of this project is to play Online music and very
easily with free of cost.
• The project “E-Music” after being tested and was found to
overcoming all the problems of the existing system. The
system is found to be error free and ready for implementation.
9. FOLLOWING ARE THE FEATURES OF
THIS PROJECT:
•Login, View all Songs Request
•Upload/delete Songs
•Login, View , play a list of Songs
•Track song request history
10. SOFTWARE REQUIRMENTS
• Operating System: Windows 7 or above
• Front End: HTML & JAVA SCRIPT,J2EE(JSPs, Servlets )
• Web Server: Apache Tomcat 8.0.35/Glassfish
• Back End : Oracle
• Tools Used: My eclipse/Eclipse/Net Beans
11. INTRODUCTION TO JAVA
• Java is a programming language initially developed by Sun
Microsystems and released as a principal component of Sun
Microsystems Java Platform. Although the language gets
much of its syntax from C and C++.
• It has a less complicated object model and lesser low-level
services. Java applications are typically compiled to byte code
(class file) that can run on any Java Virtual Machine (JVM)
regardless of computer architecture. Java is a general purpose,
object –oriented language that is specially designed to have a
few implementation dependencies as possible.
• Java is currently one of the most standard programming
languages in use, and is extensively used from application
software to web applications.
12. J2EE
• Short for Java 2 Platform Enterprise Edition,J2EE is a
platform independent, Java centric environment from Sun for
developing and deploying web based enterprise applications
online. The J2EE platform consist of a services, APIs, and
protocols that provide the functionality multitier, Web-based
applications
• Some of the key features and services of J2EE-
• At the client tier, J2EE supports pure HTML, as well as Java
applets or applications. It relies on Java Server Pages and
Servlet code to create HTML or other formatted data for the
client.
• Enterprise Java Beans (EJBs) provide another layer where the
platform’s logic is stored. An EJB server provides functions
such as threading, Concurrency, Security, and memory
management. These Services are transparent to the author.
13. MVC ARCHITECTURE
• Model-View –Controller (MVC) is an architecture tat separates the
representation of information from the user’s interface with it. The mode
consists of application data and business rules, and the controller mediates
input, converting it to commands for the model or view. A view can be
any output representation data ,such as chart or a diagram. Multiple views
of the same data are possible, such as a pie chart for management and a
tabular view for accountants .The central idea behind MVC is code
reusability and separation of concerns.
15. JAVA SERVER PAGES
• Java Server Pages(JSP) is technology that helps software
developers create dynamically generated web pages based on
HTML, XML, or other document types. Released in 1999 by
Sun Microsystems. JSP is similar to PHP, but it uses the Java
programming language.
• To deploy and run Java Server Pages, a compatible web server
with a servlet container, such as Apache Tomcat or Jetty is
required.
• Java Server pages is a technology which permits software
developers to create dynamic request like HTML, XML in
order to answer to client request in the net. The syntax in Java
Server Pages includes a supplementary XML tag which is
known as JSP actions.
16. JAVA BEANS
• Java Beans are reusable software components for Java that can
be manipulated visually in a builder tool. Practically ,they are
classes written in the Java Programming language conforming
to a particular convection. They are used to encapsulate many
objects into a single object (the bean) so that they can be
passed around as a single bean object instead of as multiple
individual objects. A Java Bean is a Java Object that is
serializable, has a null constructor, and allows access to
properties using getter and setter methods.
17. SERVLETS
• When we run small Java programs within a browser these are
referred to as Applets. . .
• so we run small Java programs within a server these are “
Servlet ”
• A servlet is a program designed to process a client request
(which requires interactivity).
– It processes arguments and formats its results as a short
lived document.
• HTML servlets are becoming a popular mechanism for
creating interactive servers.
18. SERVLETS AND JSP
• Java Server Pages is an extension to the servlets API.
• With conventional servlets you embed the HTML that you
need inside a Java program.
• With JSP you embed your Java program within a HTML
document (by using special tags).
• Works rather like JavaScript but the JSP script runs on the
server before the page is dispatched to the user’s browser.
19. HOW SERVLET WORKS?
THE JAVA SERVLET API
•The Java Servlet API is a set of Java classes which define a
standard interface between a Web client and a Web servlet.
Client requests are made to the Web server, which then invokes
the servlet to service the request through this interface.
•The API is composed of two packages:
•Java x .servlet
•Java x. Servlet .http
•The Servlet interface class is the central abstraction of the Java
Servlet API. This class defines the methods which servlets must
implement including a service() method for the handling of
requests.
20. SERVLET INTERFACE
• The Servlet interface class is the central abstraction of the Java
Servlet API. This class defines the methods which servlets
must implement including a service() method for the handling
of requests.
• The generic Servlet class implements this interface, and
defines a generic , protocol- independent servlet.
• To write an HTTP servlet for use on the web , we will use an
even more specialized class of GenericServlet called Http
Servlet. Http Servlet provides additional methods for the
processing of HTTP requests such as GET(do Get Method)
and POST (do post method). Although our servlets may
implement a service method, in most cases we will implement
the HTTP specific request handling methods of doGet and
doPost.
21. SERVLETS LIFE CYCLE
The life cycle of a servlet can be categorized into four
parts:
•Loading and Instantiation: The servlet container loads the
servlet during startup or when the first request is made. The
loading of the servlet depends on the attribute <load on startup>
of web.xml file. If the attribute <load on startup> has a positive
value then the servlet is load with loading of the container
otherwise it load when the first request comes for service. After
loading of the servlet, the container creates the instances of the
servlet.
22. • Initialization: After creating the instances, the servlet container
calls the init() method and passes the servlet initialization
parameters to the init() method. The Init() method is called only
once throughout the life cycle of the servlet. The servlet will be
available for service if it is loaded successfully otherwise the
servlet container unloads the servlet.
• Destroying the Servlet: If the servlet is no longer needed for
servicing any request, the servlet container calls the destroy()
method. Like the init() method this method is also called only
once throughout the life cycle of the servlet. Calling the destroy()
method indicates to the servlet container not to sent the any
request for service and the servlet releases all the resources
associated with it. Java Virtual Machine claims for the memory
associated with the resources for garbage collection.
24. COOKIES & SESSIONS
COOKIE
•A Cookie is a small piece of text stored on a user’s computer by
their browser. Common uses for cookies are authentication,
storing of site preferences, shopping cart items, and server
session identification.
•Only the cookies stored by the browser that relate to the domain
in the requested URL will be sent to the server.
•In essence , a cookie is a great way of linking one page to the
next for a user’s interaction with the web site or wenb application
25. SESSION
• A Session can be defined as a server-side storage of
information that is desired to persist throughout the user’s
interaction with the web site or web application.
26. CrEatINg a SImplE SErvlEt
• Servlets are written in a similar fashion to applets
– Write a new servlet class which extends
javax.servlet.http.HttpServlet (or just implements
javax.servlet.Servlet)
– Override certain methods to deal with requests
– Get your methods to create an HTML document to return
information to the client’s browser
– Load the servlet byte codes onto your web server (for
example apache/jserv)
27. JDBC
• The Java Database Connectivity (JDBC). API is the industry
standard for database –Independent connectivity between the
Java Programming language and a wide range of databases –
SQL databases and other tabular data sources, such as
spreadsheets or flat files. The JDBC API provides a call-level
API for SQL – based database access.
• JDBC technology allows you to use the programming
language to exploit” Write Once, Runs Anywhere” capabilities
for applications that require access to enterprise data. With a
JDBC technology enabled driver, you can connect all
corporate data even in a heterogeneous environment.
28. CONClUSIONS
• An E Music library is a project developed in Java to manage
your music store. User can login, Register and creates its own
music library, add songs, request to upload songs to
administrator. The main aim of creating this Online Music Store
System Java based web application is to provide user friendly
tool for music web sites.
29. rEFErENCES
• For information about HTML try http://www.w3schools.com
• You can download Sun’s servlet development kit from their
web site at the http://java.sun.com/products/servlet
• You can download apache’s Tomcat server from
http://jakarta.apache.org
• For other information about Servlet development try
http://www.servlets.com