WTL Assignment No.6.
WTL Assignment No.6.
Assignment No: 6
Title: Design and develop suitable web application using JSP, Servlet and MySQL (Backend).
Objective:
Problem Statement
Implement the program demonstrating the use of JSP.
e.g., Create a database table student info (stud id, stud name, class, division, city) using database
like Oracle/MySQL etc. and display (use SQL select query) the table content using JSP.
Outcomes
Theory
Java Server Pages (JSP): It is a server-side programming technology that is used to create
dynamic web-based applications. JSP have right to use the complete Java APIs, including the
JDBC API to access the databases. It is a technology that helps software developers to create
dynamic web pages based on HTML, XML and other document types.
It was released in 1999 by Sun Microsystems. It is just like a PHP and ASP, but it uses the Java
programming language. A JSP element is a type of java servlet that is designed to accomplish the
role of a user interface for a java web application. Web developers write JSPs as text files that
combine HTML or XHTML code, XML elements, and rooted JSP actions and commands.
Using JSP, you can collect input from users through webpage forms, current records from a
database or another source and create web pages dynamically. JSP tags can be used for different
purposes, such as retrieving information from a database or registering user preferences,
accessing JavaBeans components, passing control between pages, and sharing information
between requests, pages etc.
Architecture of JSP
1. The request / response part of a JSP is defined in below architecture
2. The client-initiated request for a JSP file using browser
3. Webs server (i.e, JSP Engine) invokes the JSP file and interpret the JSP file produce a java
code. The created java code will be a Servlet.
4. Once Servlet is created, JSP engine compiles the servlet. Compilation errors will be detected
in this phase.
5. Now servlet class is loaded by the container and executes it.
6. Engine sends the response back to the client.
Figure: Architecture of JSP
The JSP declaration tag is used to declare fields and methods. The code written inside the jsp
declaration tag is placed outside the service () method of auto generated servlet.
Servlet:
A servlet is server-side programming language in Java. Servlet is web component that is
deployed on the server for creating the dynamic web content/page. A java servlet is a java
program that extends the capabilities of a server. Although server can respond to any types of
requests they must commonly executes application hosted on web server.
Advantages of a Servlet:
• Servlets provide component based and platform-independent methods for building Web based
applications.
• Each Request is run in a separate thread, so servlet request processing is faster than CGI.
• Servlets overcomes the limitations of CGI program.
• Servlets run on Java Virtual Machine and in any platform and it is simple to write.
• Servlet are more powerful and the performance is better.
• Servlets are platform-independent.
• A servlet handles concurrent requests
• Handling HTTP requests and send text and data back to the client is made easy by servlet
request and response objects.
Disadvantages of a Servlet:
• Servlets often contain both business logic and presentation logic so it makes application
difficult to understand.
• You would need JRE to be installed to run a servlet program.
Servlet API:
The Servlet API is supported by all Servlet containers, such as Tomcat and Weblogic, etc. The
Application Programming Interface (API) contains interface and classes to write a servlet
program. The servlet API contains two packages as listed below:
• javax.servlet
• javax.servlet.http
Servlet Lifecycle:
Servlets are small programs that run at server side and creates dynamic web pages. Servlets
respond to any type of requests sent by user. In MVC architecture servlet act as controller. The
controller is the logic that processes and responds to the user requests.
Life Cycle of Servlets contain following steps:
• Load servlet class.
• Create servlet instance.
• Call the init method.
• Call the service method.
• Call the destroy method.
3. Databases: MySQL
NetBeans: It is an IDE used for quickly and easily developing java desktop and mobile and web
applications as well as HTML5 Applications with HTML JavaScript and CSS. Also provides
huge set of tools for PHP and C/C++ developers. It is free and Open-Source tool and has a great
community of users and developers around the world.
MySQL: MySQL is a widely used relational database management system (RDBMS) based on
the Structured Query Language, which is the popular language for accessing and managing the
records in the database. MySQL is free and open-source. MySQL is ideal for both small and
large applications. t is commonly used in conjunction with PHP scripts for creating powerful and
dynamic server-side or web-based enterprise applications.
MySQL supports many Operating Systems like Windows, Linux, MacOS, etc. with C, C++,
and Java languages.
Test Cases
Manual Testing is used to validate the student info (stud id, stud name, class, division, city) using
database.
Conclusion
Hence, we have performed the dynamic web application using Servlet and MySQL.