Web Application
Web Application
At
Presented to
15/06/17 to 30/07/17
Date: 25/07/17
CERTIFICATE
th
This is to certify that Miss. Aishwarya Srivastava, student of B.Tech 4 year, Computer Science &
Engineering Department of College of Engineering Roorkee has undergone summer training in Web
th th
Application Department at Centre For Railway Information System, New Delhi from 15 June to 30 July
2017 under the overall guidance of Miss. Varsha Mittal (Assistant Software Engineer).
Miss. Aishwarya Srivastava has successfully completed her training and submitted the training project report.
During the period of training she was found sincere punctual and regular. Her conduct and behavior was very
good.
Varsha Mittal
CRIS (India)
ACKNOWLEDGEMENT
th
In my 4 Semester of B. Tech College, College of Engineering Roorkee, Roorkee. I was selected as an Intern by
Centre For Railway Information System (an organization under Ministry of Railway), India. First I would like to
thank CRIS, India for giving me opportunity to learn and get exposure of the industry. Mr. Pitamber Verma Sir
CPW, WA a d Ms. Varsha Mittal Ma’a , ho ga e e oti atio to lear a d de elop the proje t. During
the training period in CRIS I was engaged in development of Dynamic Web pages. I worked in the department
We Appli atio .
Furthermore, I got the chance to gain experience for the exposure of office life. Now I am very positive that I
can connect all files which build up to become a Dynamic Web Application, which have been discussed in the
office, with practical experiences. In the Internet, I could see many dynamic web application and mobile
application especially the IRCTC Website. At the end I would like to thank all the employees at CRIS India.
Thank you for exercising patience and supporting me all the time as well as answering all my questions during
this ter . Espe iall I a t to e phasize olleagues of the depart e t We Appli atio ho ade it
very easy for me to make new friends and complete my project.
Aishwarya Srivastava
th
B.Tech (4 year)
The Centre for Railway Information Systems designs, develops, implements and maintains most of
the important information systems of Indian Railways. It is located in Chanakyapuri, New Delhi. CRIS
was established in 1986 by the Ministry of Railways of India.
In 1982, Indian Railways (IR) set up a central organization (COFOIS) to computerize freight
operations. In 1986 the Ministry of Railways saw the need for a dedicated, autonomous organization
and established CRIS, an umbrella organization for all information technology-related activities on
Indian Railways. It was entrusted with the task of designing, developing and implementing the
Freight Operations Information System (FOIS) and its communications infrastructure. CRIS began
functioning in July 1986 as an autonomous organization headed by an Executive Director (later
predesignated Managing Director).
A unique feature of CRIS is collaboration by IT specialists and railway experts on deputation from the
Indian Railways. Systems managed by CRIS have received international recognition from
Computerworld.
CRIS held a symposium, "IT Can Happen in Government", in New Delhi on 1 July 2010. The
symposium explored the challenges faced by government agencies in meeting their IT needs and
creating IT systems. In July 2014, a Seminar on Big Data was held, followed by a Symposium on Smart
Cities in July 2015.
CRIS designs, develops, implements and maintains information systems for Indian Railways. In
addition, CRIS has developed, implemented and maintained IT systems for the Andaman and Nicobar
Islands (the A & N Ship Ticketing system). The number of projects handled by CRIS has increased
from three in 2000 to more than 40 by 2016.
DYNAMIC WEB APPLICATION
A server-side dynamic web page is a web page whose construction is controlled by an application
server processing server-side scripts. In server-side scripting, parameters determine how the
assembly of every new web page proceeds, including the setting up of more client-side processing. A
client-side dynamic web page processes the web page using HTML scripting running in the browser
as it loads. JavaScript and other scripting languages determine the way the HTML in the received
page is parsed into the Document Object Model, or DOM, that represents the loaded web page. The
same client-side techniques can then dynamically update or change the DOM in the same way.
A dynamic web page is then reloaded by the user or by a computer program to change some
variable content. The updating information could come from the server, or from changes made to
that page's DOM. Using Ajax technologies the end user gets one dynamic page managed as a single
page in the web browser while the actual web content rendered on that page can vary.
DHTML is the umbrella term for technologies and methods used to create web pages that are
not static web pages. Client-side-scripting, server-side scripting, or a combination of these make for
the dynamic web experience in a browser.
Classical hypertext navigation, with HTML or XHTML alone, provides "static" content, meaning that
the user requests a web page and simply views the page and the information on that page.
However, a web page can also provide a "live", "dynamic", or "interactive" user experience. Content
(text, images, form fields, etc.) on a web page can change, in response to different contexts or
conditions.
There are two ways to create this kind of effect:
Using client-side scripting to change interface behaviors within a specific web page, in response
to mouse or keyboard actions or at specified timing events. In this case the dynamic behavior
occurs within the presentation.
Using server-side scripting to change the supplied page source between pages, adjusting the
sequence or reload of the web pages or web content supplied to the browser. Server responses may
be determined by such conditions as data in a posted HTML form, parameters in the URL, the type
of browser being used, the passage of time, or a database or server state.
Client-side scripting languages like JavaScript or ActionScript, used for Dynamic HTML (DHTML)
and Flash technologies respectively, are frequently used to orchestrate media types (sound,
animations, changing text, etc.) of the presentation. Web pages that use server-side scripting are
often created with the help of server-side languages such
as PHP, Perl, ASP, ASP.NET, JSP, ColdFusion and other languages. These server-side languages
typically use the Common Gateway Interface (CGI) to produce dynamic web pages. These kinds of
pages can also use, on the client-side, the first kind (DHTML, etc.).
LANGUAGES USED
JSP
JavaServer Pages (JSP) is a technology that helps software developers create dynamically generated
web pages based on HTML, XML, or other document types. Released in 1999 by Sun Microsystems,
[1]
JSP is similar to PHP and ASP, but it uses the Java programming language.
To deploy and run JavaServer Pages, a compatible web server with a servlet container,
such as Apache Tomcat or Jetty, is required.
Architecturally, JSP may be viewed as a high-level abstraction of Java servlets. JSPs are translated
into servlets at runtime, therefore JSP is a Servlet; each JSP servlet is cached and re-used until the
original JSP is modified.
JSP allows Java code and certain pre-defined actions to be interleaved with static web markup
content, such as HTML, with the resulting page being compiled and executed on the server to deliver
a document. The compiled pages, as well as any dependent Java libraries, contain Java bytecode
rather than machine code. Like any other Java program, they must be executed within a Java virtual
machine (JVM) that interacts with the server's host operating system to provide an abstract,
platform-neutral environment.
JSPs are usually used to deliver HTML and XML documents, but through the use of
OutputStream, they can deliver other types of data as well.
The Web container creates JSP implicit objects like request, response, session, application, config,
page, pageContext, out and exception. JSP Engine creates these objects during translation phase.
SYNTAX
JSP pages use several delimiters for scripting functions. The most basic is <% ... %>, which encloses a
JSP scriptlet. A scriptlet is a fragment of Java code that is run when the user requests the page. Other
common delimiters include <%= ... %> for expressions, where the scriptlet and delimiters are
replaced with the result of evaluating the expression, and directives, denoted with <%@ ... %>.
Java code is not required to be complete or self-contained within a single scriptlet block. It can
straddle markup content, provided that the page as a whole is syntactically correct. For example, any
Java if/for/while blocks opened in one scriptlet must be correctly closed in a later scriptlet for the
page to successfully compile.
Content that falls inside a split block of Java code (spanning multiple scriptlets) is subject to that
code. Content inside an if block will only appear in the output when the if condition evaluates to
true. Likewise, content inside a loop construct may appear multiple times in the output, depending
upon how many times the loop body runs.
The following would be a valid for loop in a JSP page:
<p>Counting to three:</p>
<% for (int i=1; i<4; i++) { %>
<p>This number is <%= i %>.</p>
<%}%>
<p>OK.</p>
The output displayed in the user's web browser would be:
Counting to three:
This number is 1.
This number is 2.
This number is 3.
OK.
Expression Language
Version 2.0 of the JSP specification added support for the Expression Language (EL), used to access
data and functions in Java objects. In JSP 2.1, it was folded into the Unified Expression Language,
which is also used in JavaServer Faces.
An example of EL Syntax:
The value of "variable" in the object "javabean" is ${javabean.variable}.
Additional tag
The JSP syntax add additional tags, called JSP actions, to invoke built-in functionality. Additionally,
the technology allows for the creation of custom JSP tag libraries that act as extensions to the
standard JSP syntax. One such library is the JSTL, with support for common tasks such as iteration
and conditionals (the equivalent of "for" and "if" statements in Java.
COMPILER
A JavaServer Pages compiler is a program that parses JSPs, and transforms them into
executable Java Servlets. A program of this type is usually embedded into the application server and
run automatically the first time a JSP is accessed, but pages may also be precompiled for better
performance, or compiled as a part of the build process to test for errors.
Some JSP containers support configuring how often the container checks JSP file timestamps to see
whether the page has changed. Typically, this timestamp would be set to a short interval (perhaps
seconds) during software development, and a longer interval (perhaps minutes, or even never) for a
deployed Web application.
HTML
Hypertext Markup Language (HTML) is the standard markup language for creating web
pages and web applications. With Cascading Style Sheets (CSS) and JavaScript it forms a triad of
[1]
cornerstone technologies for the World Wide Web. Web browsers receive HTML documents from
a webserver or from local storage and render them into multimedia web pages. HTML describes the
structure of a web page semantically and originally included cues for the appearance of the
document.
HTML elements are the building blocks of HTML pages. With HTML constructs, images and other
objects, such as interactive forms,may be embedded into the rendered page. It provides a means to
create structured documents by denoting structural semantics for text such as headings, paragraphs,
lists, links, quotes and other items. HTML elements are delineated by tags, written using angle
brackets. Tags such as <img /> and <input /> introduce content into the page directly. Others such as
<p>...</p> surround and provide information about document text and may include other tags as
sub-elements. Browsers do not display the HTML tags, but use them to interpret the content of the
page.
HTML can embed programs written in a scripting language such as JavaScript which affect the
behavior and content of web pages. Inclusion of CSS defines the look and layout of content.
The World Wide Web Consortium (W3C), maintainer of both the HTML and the CSS standards,
has encouraged the use of CSS over explicit presentational HTML since 1997.
DEVELOPMENT
In 1980, physicist Tim Berners-Lee, a contractor at CERN, proposed and prototyped ENQUIRE, a
system for CERN researchers to use and share documents. In 1989, Berners-Lee wrote a memo
[3]
proposing an Internet-based hypertext system. Berners-Lee specified HTML and wrote the
browser and server software in late 1990. That year, Berners-Lee and CERN data systems engineer
Robert Cailliau collaborated on a joint request for funding, but the project was not formally adopted
by CERN. In his personal notes from 1990 he listed "some of the many areas in which hypertext is
used" and put an encyclopedia first.
The first publicly available description of HTML was a document called "HTML Tags", first mentioned
on the Internet by Tim Berners-Lee in late 1991. It describes 18 elements comprising the initial,
relatively simple design of HTML. Except for the hyperlink tag, these were strongly influenced
by SGMLguid, an in-house Standard Generalized Markup Language (SGML)-based
documentation format at CERN. Eleven of these elements still exist in HTML 4.
HTML is a markup language that web browsers use to interpret and compose text, images, and other
material into visual or audible web pages. Default characteristics for every item of HTML markup are
defined in the browser, and these characteristics can be altered or enhanced by the web page
designer's additional use of CSS. Many of the text elements are found in the 1988 ISO technical
report TR 9537 Techniques for using SGML, which in turn covers the features of early text formatting
languages such as that used by the RUNOFF command developed in the early 1960s for
the CTSS (Compatible Time-Sharing System) operating system: these formatting commands were
derived from the commands used by typesetters to manually format documents. However, the
SGML concept of generalized markup is based on elements (nested annotated ranges with
attributes) rather than merely print effects, with also the separation of structure and markup; HTML
has been progressively moved in this direction with CSS. Berners-Lee considered HTML to be an
application of SGML. It was formally defined as such by
the Internet Engineering Task Force (IETF) with the mid-1993 publication of the first proposal for an
HTML specification, the "Hypertext Markup Language (HTML)" Internet Draft by Berners-Lee and Dan
[9][10]
Connolly, which included an SGML Document Type Definition to define the grammar. The draft
expired after six months, but was notable for its acknowledgment of the NCSA Mosaic browser's
custom tag for embedding in-line images, reflecting the IETF's philosophy of basing standards on
successful prototypes. Similarly, Dave Raggett's competing Internet-Draft, "HTML+ (Hypertext
Markup Format)", from late 1993, suggested standardizing already-implemented features like tables
and fill-out forms.
After the HTML and HTML+ drafts expired in early 1994, the IETF created an HTML Working Group,
which in 1995 completed "HTML 2.0", the first HTML specification intended to be treated as a
standard against which future implementations should be based.
Further development under the auspices of the IETF was stalled by competing interests. Since 1996,
the HTML specifications have been maintained, with input from commercial software vendors, by
the World Wide Web Consortium (W3C). However, in 2000, HTML also became an international
standard (ISO/IEC 15445:2000). HTML 4.01 was published in late 1999, with further errata published
through 2001. In 2004, development began on HTML5 in the Web Hypertext Application Technology
Working Group (WHATWG), which became a joint deliverable with the W3C in 2008, and completed
and standardized on 28 October 2014.
JAVA (Servlet)
A Java servlet is a Java program that extends the capabilities of a server. Although servlets can
respond to any types of requests, they most commonly implement applications hosted on Web
[1]
servers. Such Web servlets are the Java counterpart to other dynamic Web content
technologies such as PHP and ASP.NET.
INTRODUCTION
A Java servlet processes or stores a Java class in Java EE that conforms to the Java Servlet API, a
standard for implementing Java classes that respond to requests. Servlets could in principle
communicate over any client–server protocol, but they are most often used with the HTTP protocol.
Thus "servlet" is often used as shorthand for "HTTP servlet". Thus, a software developer may use a
servlet to add dynamic content to a web server using the Java platform. The generated content is
commonly HTML, but may be other data such as XML. Servlets can
maintain state in session variables across many server transactions by using HTTP cookies, or URL
rewriting.
To deploy and run a servlet, a web container must be used. A web container (also known as a
servlet container) is essentially the component of a web server that interacts with the servlets. The
web container is responsible for managing the lifecycle of servlets, mapping a URL to a particular
servlet and ensuring that the URL requester has the correct access rights.
The Servlet API, contained in the Java package hierarchy javax.servlet , defines the expected
interactions of the web container and a servlet.
A Servlet is an object that receives a request and generates a response based on that request. The
basic Servlet package defines Java objects to represent servlet requests and responses, as well as
objects to reflect the servlet's configuration parameters and execution environment. The package
javax.servlet.http defines HTTP-specific subclasses of the generic servlet elements, including
session management objects that track multiple requests and responses between the web server
and a client. Servlets may be packaged in a WAR file as a web application.
Servlets can be generated automatically from JavaServer Pages (JSP) by the JavaServer Pages
compiler. The difference between servlets and JSP is that servlets typically embed HTML inside Java
code, while JSPs embed Java code in HTML. While the direct usage of servlets to generate HTML (as
shown in the example below) has become rare, the higher level MVC web framework in Java EE (JSF)
still explicitly uses the servlet technology for the low level request/response handling via
the FacesServlet . A somewhat older usage is to use servlets in conjunction with JSPs in a pattern
called "Model 2", which is a flavor of the model–view–controller.
The current version of Servlet is 3.1.
LIFE CYCLE OF SERVLET
Three methods are central to the life cycle of a servlet. These are init() , service() , and destroy() .
They are implemented by every servlet and are invoked at specific times by the server.
During initialization stage of the servlet life cycle, the web container initializes the servlet instance
by calling the init() method, passing an object implementing the javax.servlet.ServletConfig
interface. This configuration object allows the servlet to access name-value initialization parameters
from the web application.
After initialization, the servlet instance can service client requests. Each request is serviced in its own
separate thread. The web container calls the service() method of the servlet for every request.
The service() method determines the kind of request being made and dispatches it to an appropriate
method to handle the request. The developer of the servlet must provide an implementation for
these methods. If a request is made for a method that is not implemented by the servlet, the
method of the parent class is called, typically resulting in an error being returned to the requester.
Finally, the web container calls the destroy() method that takes the servlet out of service.
The destroy() method, like init() , is called only once in the lifecycle of a servlet.
The following is a typical user scenario of these methods.
Assume that a user requests to visit a URL.
The browser then generates an HTTP request for this URL.
This request is then sent to the appropriate server.
The HTTP request is received by the web server and forwarded to the servlet container.
The container maps this request to a particular servlet.
The servlet is dynamically retrieved and loaded into the address space of the container.
The container invokes the init() method of the servlet.
This method is invoked only when the servlet is first loaded into memory.
It is possible to pass initialization parameters to the servlet so that it may configure itself.
The container invokes the service() method of the servlet.
This method is called to process the HTTP request.
The servlet may read data that has been provided in the HTTP request.
The servlet may also formulate an HTTP response for the client.
The servlet remains in the container's address space and is available to process any other HTTP
requests received from clients.
The service() method is called for each HTTP request.
The container may, at some point, decide to unload the servlet from its memory.
The algorithms by which this decision is made are specific to each container.
The container calls the servlet's destroy() method to relinquish any resources such as file handles
that are allocated for the servlet; important data may be saved to a persistent store.
The memory allocated for the servlet and its objects can then be garbage collected.
EXAMPLE
The following example servlet prints how many times its service() method was called.
methods doGet() , doPost() , doPut() , doDelete() , and so on; according to the HTTP request. In the
example below service() is overridden and does not distinguish which HTTP request method it
serves.
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
FEATURES
MySQL is offered under two different editions: the open source MySQL Community Server and the
proprietary Enterprise Server. MySQL Enterprise Server is differentiated by a series of proprietary
extensions which install as server plugins, but otherwise shares the version numbering system and is
built from the same code base.
Major features as available in MySQL 5.6:
A broad subset of ANSI SQL 99, as well as extensions
Cross-platform support
Stored procedures, using a procedural language that closely adheres to SQL/PSM
Triggers
Cursors
Updatable views
Online DDL when using the InnoDB Storage Engine.
Information schema
Performance Schema that collects and aggregates statistics about server execution and
with one master per slave, many slaves per master. Multi-master replication is provided
in MySQL Cluster, and multi-master support can be added to unclustered configurations
using Galera Cluster.
Full-text indexing and searching
Embedded database library
Unicode support
Partitioned tables with pruning of partitions in optimizer
Shared-nothing clustering through MySQL Cluster
Multiple storage engines, allowing one to choose the one that is most effective for each
Eclipse- NEON
Eclipse is an integrated development environment (IDE) used in computer programming, and is the
most widely used Java IDE. It contains a base workspace and an extensible plug-in system for
customizing the environment. Eclipse is written mostly in Java and its primary use is for developing
Java applications, but it may also be used to develop applications in other programming languages
via plug-ins, including Ada, ABAP, C, C++, COBOL, D, Fortran, Haskell, JavaScript, Julia, Lasso, Lua,
NATURAL, Perl, PHP, Prolog, Python, R, Ruby (including Ruby on
Rails framework), Rust, Scala, Clojure, Groovy, Scheme, and Erlang. It can also be used to develop
documents with LaTeX (via a TeXlipse plug-in) and packages for the software Mathematica.
Development environments include the Eclipse Java development tools (JDT) for Java and Scala,
Eclipse CDT for C/C++, and Eclipse PDT for PHP, among others.
The initial codebase originated from IBM VisualAge. The Eclipse software development kit (SDK),
which includes the Java development tools, is meant for Java developers. Users can extend its
abilities by installing plug-ins written for the Eclipse Platform, such as development toolkits for other
programming languages, and can write and contribute their own plug-in modules. Since the
introduction of the OSGi implementation ( Equinox) in version 3 of Eclipse, plug-ins can be plugged-
stopped dynamically and are termed (OSGI) bundles.
Eclipse software development kit (SDK) is free and open-source software, released under the terms
of the Eclipse Public License, although it is incompatible with the GNU General Public License. It was
one of the first IDEs to run under GNU Classpath and it runs without problems under IcedTea.
HISTORY
Eclipse was inspired by the Smalltalk-based VisualAge family of integrated development environment
(IDE) products. Although fairly successful, a major drawback of the VisualAge products was that
developed code was not in a component-based software engineering model. Instead, all code for a
project was held in a compressed lump (somewhat like a zip file but in a proprietary format called .dat).
Individual classes could not be easily accessed, certainly not outside the tool. A team primarily at the
IBM Cary NC lab developed the new product as a Java-based replacement. In November 2001, a
consortium was formed with a board of stewards to further the development of Eclipse as open-source
software. It is estimated that IBM had already invested nearly $40 million by that time. The original
members were Borland, IBM, Merant, QNX Software Systems, Rational
[13]
Software, Red Hat, SuSE, TogetherSoft, and WebGain. The number of stewards increased to
over 80 by the end of 2003. In January 2004, the Eclipse Foundation was created.
Eclipse 3.0 (released on 21 June 2004) selected the OSGi Service Platform specifications as the
runtime architecture.
The Association for Computing Machinery recognized Eclipse with the 2011 ACM Software Systems
Award on 26 April 2012.
ARCHITECTURE
Eclipse uses plug-ins to provide all the functionality within and on top of the runtime system. Its runtime
[41]
system is based on Equinox, an implementation of the OSGi core framework specification. In addition
to allowing the Eclipse Platform to be extended using other programming languages, such as C and
Python, the plug-in framework allows the Eclipse Platform to work with typesetting languages like LaTeX
and networking applications such as telnet and database management systems. The plug-in architecture
supports writing any desired extension to the environment, such as
for configuration management. Java and CVS support is provided in the Eclipse SDK, with support for
other version control systems provided by third-party plug-ins.
With the exception of a small run-time kernel, everything in Eclipse is a plug-in. Thus, every plug-in
developed integrates with Eclipse in the same way as other plug-ins; in this respect, all features are
[citation needed]
"created equal". Eclipse provides plug-ins for a wide variety of features, some of
which are from third parties using both free and commercial models. Examples of plug-ins include
for Unified Modeling Language (UML), for Sequence and other UML diagrams, a plug-in for
DB Explorer, and many more.
The Eclipse SDK includes the Eclipse Java development tools (JDT), offering an IDE with a built-in
Java incremental compiler and a full model of the Java source files. This allows for
advanced refactoring techniques and code analysis. The IDE also makes use of a workspace, in this
case a set of metadata over a flat filespace allowing external file modifications as long as the
corresponding workspace resource is refreshed afterward.
Eclipse implements the graphical control elements of the Java toolkit called Standard Widget Toolkit
(SWT), whereas most Java applications use the Java standard Abstract Window Toolkit (AWT) or
Swing. Eclipse's user interface also uses an intermediate graphical user interface layer
called JFace, which simplifies the construction of applications based on SWT. Eclipse was made to
run on Wayland during a Google Summer of Code (GSoC) Project in 2014.
As of 2017, language packs being developed by the Babel Project provide translations into over
40 natural languages.
Apache Tomcat
Apache Tomcat, often referred to as Tomcat Server, is an open-source Java Servlet
Container developed by the Apache Software Foundation (ASF). Tomcat implements several Java
EE specifications including Java Servlet, JavaServer Pages (JSP), Java EL, and WebSocket, and provides
a "pure Java" HTTP web server environment in which Java code can run.
Tomcat is developed and maintained by an open community of developers under the auspices of the
Apache Software Foundation, released under the Apache License 2.0 license, and is open-source
software.
COMPONENTS
Tomcat 4.x was released with Catalina (a servlet container), Coyote (an HTTP connector) and Jasper
(a JSP engine).
Catalina
Catalina is Tomcat's servlet container. Catalina implements Sun Microsystems's specifications for
servlet and JavaServer Pages (JSP). In Tomcat, a Realm element represents a "database" of
usernames, passwords, and roles (similar to Unix groups) assigned to those users. Different
implementations of Realm allow Catalina to be integrated into environments where such
authentication information is already being created and maintained, and then use that information
to implement Container Managed Security as described in the Servlet Specification.
Coyote
Coyote is a Connector component for Tomcat that supports the HTTP 1.1 protocol as a web server.
This allows Catalina, nominally a Java Servlet or JSP container, to also act as a plain web server that
serves local files as HTTP documents.
Coyote listens for incoming connections to the server on a specific TCP port and forwards the
request to the Tomcat Engine to process the request and send back a response to the requesting
client. Another Coyote Connector, Coyote JK, listens similarly but instead forwards its requests to
another web server, such as Apache, using the JK protocol. This usually offers better performance.
Jasper
Jasper is Tomcat's JSP Engine. Jasper parses JSP files to compile them into Java code as servlets
(that can be handled by Catalina). At runtime, Jasper detects changes to JSP files and recompiles
them. As of version 5, Tomcat uses Jasper 2, which is an implementation of the Sun Microsystems's
JSP 2.0 specification. From Jasper to Jasper 2, important features were added:
JSP Tag library pooling - Each tag markup in JSP file is handled by a tag handler class. Tag
handler class objects can be pooled and reused in the whole JSP servlet.
Background JSP compilation - While recompiling modified JSP Java code, the older version is still
available for server requests. The older JSP servlet is deleted once the new JSP servlet has finished
being recompiled.
Recompile JSP when included page changes - Pages can be inserted and included into a JSP at
runtime. The JSP will not only be recompiled with JSP file changes but also with included
page changes.
JDT Java compiler - Jasper 2 can use the Eclipse JDT (Java Development Tools) Java compiler instead
of Ant and javac .
Three new components were added with the release of Tomcat 7:
Cluster
This component has been added to manage large applications. It is used for load balancing that
can be achieved through many techniques. Clustering support currently requires the JDK version
1.5 or higher.
High availability
A high-availability feature has been added to facilitate the scheduling of system upgrades (e.g.
new releases, change requests) without affecting the live environment. This is done by dispatching
live traffic requests to a temporary server on a different port while the main server is upgraded on
the main port. It is very useful in handling user requests on high-traffic web applications.
Web application
It has also added user- as well as system-based web applications enhancement to add support
for deployment across the variety of environments. It also tries to manage sessions as well as
applications across the network.
Tomcat is building additional components. A number of additional components may be used
with Apache Tomcat. These components may be built by users should they need them or they
can be downloaded from one of the mirrors.
FEATURES
Tomcat 7.x implements the Servlet 3.0 and JSP 2.2 specifications. It requires Java version 1.6,
although previous versions have run on Java 1.1 through 1.5. Versions 5 through 6 saw
improvements in garbage collection, JSP parsing, performance and scalability. Native wrappers,
known as "Tomcat Native", are available for Microsoft Windows and Unix for platform integration.
Tomcat 8.x implements the Servlet 3.1 and JSP 2.4 Specifications. Apache Tomcat 8.5.x is intended to
replace 8.0.x and includes new features pulled forward from Tomcat 9.0.x. The minimum Java
version and implemented specification versions remain unchanged.
SQLyog Community
SQLyog is a GUI tool for the RDBMS MySQL. It is developed by Webyog, Inc. based in Bangalore, India
and Santa Clara California. SQLyog is being used by more than 30,000 customers worldwide and has
been downloaded more than 2,000,000 times
HISTORY
SQLyog v0.9 was first released to the public in 2001 as after eight months of development. SQLyog
was available free of charge, but with closed source code, until v3.0 when it was made a fully
commercial software. Nowadays SQLyog is distributed both as free software free of charge as well as
several paid, proprietary, versions. The free software version is known as Community
Edition at Google Code. Paid versions are sold as Professional, Enterprise and Ultimate Editions.
FEATURES
The DBMS parses, compiles, and performs query optimization on the statement template, and stores
the result without executing it.
Execute: At a later time, the application supplies (or binds) values for the parameters, and the
DBMS executes the statement (possibly returning a result). The application may execute the
statement as many times as it wants with different values. In this example, it might supply 'Bread'
for the first parameter and '1.00' for the second parameter.
As compared to executing SQL statements directly, prepared statements offer two main advantages:
The overhead of compiling and optimizing the statement is incurred only once, although the
statement is executed multiple times. Not all optimization can be performed at the time the
prepared statement is compiled, for two reasons: the best plan may depend on the specific values of
the parameters, and the best plan may change as tables and indexes change over time.
Prepared statements are resilient against SQL injection, because parameter values, which are
transmitted later using a different protocol, need not be correctly escaped. If the original statement
template is not derived from external input, SQL injection cannot occur.
On the other hand, if a query is executed only once, server-side prepared statements can be slower
because of the additional round-trip to the server. Implementation limitations may also lead to
performance penalties; for example, some versions of MySQL did not cache results of prepared
queries. A stored procedure, which is also precompiled and stored on the server for later execution,
has similar advantages. Unlike a stored procedure, a prepared statement is not normally written in a
procedural language and cannot use or modify variables or use control flow structures, relying
instead on the declarative database query language. Due to their simplicity and client-side
emulation, prepared statements are more portable across vendors.
Examples
Java JDBC
SOFTWARE SUPPORT
Starting with version 3.1, JDBC has been developed under the Java Community Process. JSR 54
specifies JDBC 3.0 (included in J2SE 1.4), JSR 114 specifies the JDBC Rowset additions, and JSR 221 is
the specification of JDBC 4.0 (included in Java SE 6).
JDBC 4.1, is specified by a maintenance release 1 of JSR 221 and is included in Java SE 7.
The latest version, JDBC 4.2, is specified by a maintenance release 2 of JSR 221 and is included in
Java SE 8.
FUNCTIONALITY
JDBC allows multiple implementations to exist and be used by the same application. The API provides
a mechanism for dynamically loading the correct Java packages and registering them with the JDBC
Driver Manager. The Driver Manager is used as a connection factory for creating JDBC connections.
JDBC connections support creating and executing statements. These may be update statements such
as SQL's CREATE, INSERT, UPDATE and DELETE, or they may be query statements such as SELECT.
Additionally, stored procedures may be invoked through a JDBC connection. JDBC represents
statements using one of the following classes:
Statement – the statement is sent to the database server each and every time.
PreparedStatement – the statement is cached and then the execution path is pre-determined on
the database server allowing it to be executed multiple times in an efficient manner.
CallableStatement – used for executing stored procedures on the database.
Update statements such as INSERT, UPDATE and DELETE return an update count that indicates how
many rows were affected in the database. These statements do not return any other information. Query
statements return a JDBC row result set. The row result set is used to walk over the result set. Individual
columns in a row are retrieved either by name or by column number. There may be any
number of rows in the result set. The row result set has metadata that describes the names of
the columns and their types.
There is an extension to the basic JDBC API in the javax.sql .
JDBC connections are often managed via a connection pool rather than obtained directly from the
driver.
JDBC DRIVERS
JDBC drivers are client-side adapters (installed on the client machine, not on the server) that convert
requests from Java programs to a protocol that the DBMS can understand.
Types
Commercial and free drivers provide connectivity to most relational-database servers. These drivers
fall into one of the following types:
Type 1 that calls native code of the locally available ODBC driver. (Note: In JDBC 4.2, JDBC-ODBC
bridge has been removed)
Type 2 that calls database vendor native library on a client side. This code then talks to database over
the network.
Type 3, the pure-java driver that talks with the server-side middleware that then talks to
the database.
Type 4, the pure-java driver that uses database native protocol.
Sources
Oracle provides a list of some JDBC drivers and vendors
Simba Technologies ships an SDK for building custom JDBC Drivers for any custom/proprietary
relational data source
CData Software ships type 4 JDBC Drivers for various applications, databases, and Web APIs.
RSSBus Type 4 JDBC Drivers for applications, databases, and web services
DataDirect Technologies provides a comprehensive suite of fast Type 4 JDBC drivers for all
major database they advertise as Type 5
IDS Software provides a Type 3 JDBC driver for concurrent access to all major databases.
Supported features include resultset caching, SSL encryption, custom data source, dbShield
OpenLink Software ships JDBC Drivers for a variety of databases, including Bridges to other data
access mechanisms (e.g., ODBC, JDBC) which can provide more functionality than the targeted
mechanism
JDBaccess is a Java persistence library for MySQL and Oracle which defines major database access
operations in an easy usable API above JDBC
JNetDirect provides a suite of fully Sun J2EE certified high-performance JDBC drivers.
JDBCR4 is a service program written by Scott Klement to allow access to JDBC from RPG on the IBM i.
HSQLDB is a RDBMS with a JDBC driver and is available under a BSD license.
SchemaCrawler is an open source API that leverages JDBC, and makes database metadata available
as plain old Java objects (POJOs).
Model-View-Controller
Model–view–controller (MVC) is a software architectural pattern for implementing user interfaces
on computers. It divides a given application into three interconnected parts in order to separate
internal representations of information from the ways that information is presented to and
accepted from the user. The MVC design pattern decouples these major components allowing for
efficient code reuse and parallel development.
Traditionally used for desktop graphical user interfaces (GUIs), this architecture has become popular
[3]
for designing web applications and even mobile, desktop and other clients. Popular programming
languages like Java, C#, Ruby, PHP and others have popular MVC frameworks that are currently being
used in web application development straight out of the box.
DESCRIPTION
As with other software architectures, MVC expresses the "core of the solution" to a problem while
allowing it to be adapted for each system. Particular MVC architectures can vary significantly from
the traditional description here.
Components
The model is the central component of the pattern. It expresses the application's behavior in terms
of the problem domain, independent of the user interface. It directly manages the data, logic and
rules of the application.
A view can be any output representation of information, such as a chart or a diagram. Multiple views
of the same information are possible, such as a bar chart for management and a tabular view for
accountants.
The third part, the controller, accepts input and converts it to commands for the model or view.
Intreactions
In addition to dividing the application into three kinds of components, the model–view–controller
design defines the interactions between them.
A model stores data that is retrieved according to commands from the controller and displayed in
the view.
A view generates new output to the user based on changes in the model.
A controller can send commands to the model to update the model's state (e.g., editing a document).
It can also send commands to its associated view to change the view's presentation of the model
(e.g., scrolling through a document).
ADVANTAGES AND DISADVANTAGES
Advantages
Simultaneous development – Multiple developers can work simultaneously on the model,
controller and views.
High cohesion – MVC enables logical grouping of related actions on a controller together. The views
for a specific model are also grouped together.
Low coupling – The very nature of the MVC framework is such that there is low coupling among
models, views or controllers
Ease of modification – Because of the separation of responsibilities, future development or
modification is easier
Multiple views for a model – Models can have multiple views
Disadvantages
Code navigability – The framework navigation can be complex because it introduces new layers
of abstraction and requires users to adapt to the decomposition criteria of MVC.
Multi-artifact consistency – Decomposing a feature into three artifacts causes scattering. Thus,
requiring developers to maintain the consistency of multiple representations at once.
Pronounced learning curve – Knowledge on multiple technologies becomes the norm. Developers
using MVC need to be skilled in multiple technologies.
GOALS OF MVC
Simultaneous development
Because MVC decouples the various components of an application, developers are able to work in
parallel on different components without impacting and/or blocking one another. For example, a
team might divide their developers between the front-end and the back-end. The back-end
developers can design the structure of the data and how the user interacts with it without requiring
the user interface to be completed. Conversely, the front-end developers are able to design and test
the layout of the application prior to the data structure being available.
Code reuse
By creating components that are independent of one another, developers are able to reuse
components quickly and easily in other applications. The same (or similar) view for one
application can be refactored for another application with different data because the view is
simply handling how the data is being displayed to the user.
Data Access Object
In computer software, a data access object (DAO) is an object that provides an abstract interface to
some type of database or other persistence mechanism. By mapping application calls to the
persistence layer, the DAO provides some specific data operations without exposing details of the
database. This isolation supports the Single responsibility principle. It separates what data access the
application needs, in terms of domain-specific objects and data types (the public interface of the
DAO), from how these needs can be satisfied with a specific DBMS, database schema, etc. (the
implementation of the DAO).
ADVANTAGES
The advantage of using data access objects is the relatively simple and rigorous separation between
two important parts of an application that can but should not know anything of each other, and
which can be expected to evolve frequently and independently. Changing business logic can rely on
the same DAO interface, while changes to persistence logic do not affect DAO clients as long as the
interface remains correctly implemented. All details of storage are hidden from the rest of the
application (see information hiding). Thus, possible changes to the persistence mechanism can be
implemented by just modifying one DAO implementation while the rest of the application isn't
affected. DAOs act as an intermediary between the application and the database
In the non specific context of the Java programming language, Data Access Objects as a design
concept can be implemented in a number of ways. This can range from a fairly simple interface that
separates the data access parts from the application logic, to frameworks and commercial
products. DAO coding paradigms can require some skill. Technologies like Java Persistence API and
Enterprise JavaBeans come built into application servers and can be used in applications that use a
JavaEE application server. Commercial products like TopLink are available based on Object-
relational mapping (ORM). Popular open source ORM products include Doctrine, Hibernate, iBATIS
and JPA implementations such as Apache OpenJPA.
DISADVANTAGES
Potential disadvantages of using DAO include leaky abstraction, code duplication, and abstraction
inversion. In particular, the abstraction of the DAO as a regular Java object can hide the high cost of
each database access, and can also force developers to trigger multiple database queries to retrieve
information that could otherwise be returned in a single operation with normal SQL set operations.
If an application requires multiple DAOs, one might find oneself repeating essentially the same
create, read, update, and delete code for each DAO. This boiler-plate code may be avoided however,
by implementing a generic DAO that handles these common operations.
ADVANTAGES OF JSP
ADVANTAGES OF JSP
Lear i g J“P does ’t eed stro g k o ledge of Ja a, e ause riti g a progra i J“P is othi g ut
making use of tags or we can say that it is meant for using tag based approach of programming.
JSP programming is easy to learn and easy to implement for Non-Java programmers also.
JSP programming environment provides the separation between presentation logic and business
logic.
JSP programming environment provides parallel development of web applications.
JSP programming has implicit objects.
JSP programming eliminates the repeated deployment problems i.e. as and when we change the
JSP, we need to save the JSP and makes a request and automatic deployment is taken care by
container
– JASPER [JSP Execution Environment].
JSP provides optional mechanism in configuring web application file (web.xml).
JSP environment provides implicit/global exception handling mechanism.
JSP programming provides and additional concept called Custom Tags Development.
JSP programming environment provides page compilation automatically.
ABOUT MY PROJECT
My project is based on Dynamic Web Pages Development using JSP.
This is a Complaint-registration website for a college institution. There are about seven pages in this
website.
There is the first page where you have to select what type of user you are
Existing user
New user
Admin
Ea h of the e pages are o e ted to the data ase park , here all the data is stored.
First.jsp is the first jsp page which provides us to select that what type of user we are.
Choosing the option Existing user on successful login a Complaint Registration page opens up. Where
any student can register complaint regarding any issue they are facing in the institution.
If you choose the option of new user then a Registration page opens up where any new user can
make their account and register themselves so that they can also register any complaint they come
across.
If you choose the option admin that means you are the admin of the website and have the access
of admin. Here you handle the problems. On your successful login as admin the complaint table
comes up and to resolve any of them you have to select the option resolve corresponding to each
complaint. And on clicking the resolve option the complaint resolve pages opens up where the admin
puts up their re ark a d the the resol e o plai t’s status are s it hed fro u resol ed to
resolve.
Home.jsp is the jsp page in which we input the username and password for the successful login as
the existing user. The username and password entered here are passed on to the next jsp page
login.jsp where the data is cross checked with the database that it the existing user or not.
Home.jsp
<%@ page import="java.sql.*" %>
<html>
<head>
<style type="text/css">
</style>
<script>
</script>
<title>Home</title>
<meta charset="UTF-8">
<meta name="viewpoint" content="width=device-width, initial-scale=1.0">
</head>
<style>
body
{
background-image:url("https://www.collegesearch.in/upload/institute/images/large/coer.jpg");
background-repeat:no-repeat;
background-size:cover;
}
</style>
<%
Connection con= null;
PreparedStatement ps = null;
ResultSet rs = null;
String driverName = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/park";
String user = "root";
String password = "aish";
String sql = "select USERNAME from recrd";
try {
Class.forName(driverName);
con = DriverManager.getConnection(url, user,
password); ps = con.prepareStatement(sql); rs =
ps.executeQuery();
}
catch(SQLException sqe)
{
out.println("home"+sqe);
}
%>
<form method="post" action="login.jsp">
<center><h2 style="color:green">User Login</h2></center>
<table border="1" align="center"> <tr>
<td><b>Enter Your Username:</b></td>
<td><input type="text" name="USERNAME"/></td>
</tr>
<tr>
<td><b>Enter Your Password :</b></td>
<td><input type="password" name="PASSWORD"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" name="Submit"/></td>
</table>
</form>
</body>
</html>
Logi .jsp is the jsp page here it is o e ted to the data ase park ha i g the ta le re rd . Here the data
are cross checked and matched with the data in the database if you are successfully logged
i the the e t page the o plai t registratio page ope s up here the stude ts a register their o plai ts a d
if the data does ot at h the the essage sho s up sorr our re ord is ot fou d .
Login.jsp
<%@ page import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
</head>
<body>
<%! String userdbName;
String userdbPsw;
String dbUsertype;
%>
<%
Connection con= null;
PreparedStatement ps = null;
ResultSet rs = null;
String driverName = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/park";
String user = "root";
String dbpsw = "aish";
String sql = "select * from recrd where USERNAME=? and PASSWORD=?";
String USERNAME = request.getParameter("USERNAME"); String
PASSWORD = request.getParameter("PASSWORD");
if((!(USERNAME.equals(null) || USERNAME.equals("")) && !(PASSWORD.equals(null) ||
PASSWORD.equals(""))) )
{try{
Class.forName(driverName);
con = DriverManager.getConnection(url, user, dbpsw);
ps = con.prepareStatement(sql);
ps.setString(1, USERNAME);
ps.setString(2, PASSWORD);
rs = ps.executeQuery();
if(rs.next()) {
userdbName = rs.getString("USERNAME");
userdbPsw = rs.getString("PASSWORD");
if(USERNAME.equals(userdbName) && PASSWORD.equals(userdbPsw)){
session.setAttribute("USERNAME",userdbName);
response.sendRedirect("complaint.jsp"); }
}else
response.sendRedirect("error.jsp");
rs.close();
ps.close(); }
catch(SQLException sqe) {
out.println(sqe);}
}
else{
%>
<center><p style="color:red">Error In Login</p></center>
<% getServletContext().getRequestDispatcher("/home.jsp").include(request,
response);}
%>
</body>
</html>
Error.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Error</title>
</head>
<body>
<center><p style="color:red">Sorry, your record is not available.</p></center>
<% getServletContext().getRequestDispatcher("/home.jsp").include(request,
response); %>
</body>
</html>
Complaint.jsp
<%@page import="java.sql.*"%>
<html>
<head>
<style type="text/css">
</style>
<title>Complaint Page</title>
<meta charset="UTF-8">
<meta name="viewpoint" content="width=device-width, initial-scale=1.0">
<script language="javascript" type="text/javascript">
var xmlHttp
var xmlHttp
function showsubtype(str){
if (typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP"); }
if (xmlHttp==null){
alert("Browser does not support XMLHTTP Request")
return; }
var url="subtype.jsp";
url +="?count=" +str;
xmlHttp.onreadystatechange = subtypeChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null); }
function subtypeChange(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ document.getElementById("subtype").innerHTML=xmlHttp.responseText
}}
</script>
</head>
<style>
body
{
background-image:url("https://i1.wp.com/www.faadooengineers.com/colleges/wp-
content/uploads/COLLEGE-OF-ENGINEERING-ROORKEE.jpg?w=400");
background-repeat:no-repeat;
background-size:cover;
}
</style>
<center>
<form action="ComplaintServlet" method="post">
<%
String id = (String)session.getAttribute("USERNAME");
String driverName = "com.mysql.jdbc.Driver";
String connectionUrl = "jdbc:mysql://localhost:3306/park";
String userId = "root";
String password = "aish";
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
%>
<h2 align="center"><font><strong><b><u><i>Complaint page</i></u></b></strong></font></h2>
<% try{
connection = DriverManager.getConnection(connectionUrl, userId, password);
statement=connection.createStatement();
String sql ="SELECT * FROM recrd where USERNAME='"+id+"'";
resultSet = statement.executeQuery(sql);
while(resultSet.next()){
%>
<table>
<tr>
<td><b>Username:</b></td>
<td><%=resultSet.getString("USERNAME") %></td>
</tr>
<tr>
<td><b>Name:</b></td>
<td><%=resultSet.getString("FNAME") %> <%=resultSet.getString("LNAME") %></td>
</tr>
<tr>
<td><b>Contact no:</b></td>
<td><%=resultSet.getString("PHONE") %></td>
</tr>
<tr>
<td><b>Email:</b></td>
<td><%=resultSet.getString("EMAIL") %></td>
</tr>
<%
}
} catch (Exception e) {
e.printStackTrace();
}
connection.close();
%>
<tr>
<td><b>Complaint type:</b></td>
<td><select name='complaint_type'
onchange="showsubtype(this.value)"> <option
value="none">Select</option>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/park","root","aish");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from complaint_type");
while(rs.next()){
%>
<option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>
<%
}
%>
</select>
<br>
</td>
</tr>
<tr>
<td><b>Complaint Sub-Type:</b></td>
<td>
<div id='subtype'>
<select name='subtype' >
<option value='-1'></option>
</select>
</div>
</td>
</tr>
<tr>
<td><b>Complaint Name:</b></td>
<td><input type="text" name="name" >
</td>
</tr>
<tr>
<td><b>Complaint Description:</b></td>
<td><textarea cols="40" rows="8" name="desc">
</textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
</form>
</center>
</body>
</html>
Subtype.jsp is the jsp page with the help of which we get the Dynamic Dropdown menu.
Subtype.jsp
<%@page import="java.sql.*"%>
<%
String complaint_type=request.getParameter("count");
String buffer="<select name='subtype' onchange='showsubtype(this.value);'><option value='-
1'>Select</option>";
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/park","root","aish");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from Subtype where
complaint_id='"+complaint_type+"' ");
while(rs.next()){
buffer=buffer+"<option value='"+rs.getString(1)+"'>"+rs.getString(2)+"</option>";
}
buffer=buffer+"</select>";
response.getWriter().println(buffer);
}
catch(Exception e){
System.out.println(e);
} %>
ComplaintServlet.java
package controller;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.DaoComplaint;
import model.ModelComplaint;
public class ComplaintServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String username = "";
String name = request.getParameter("name");
String complaint_type = request.getParameter("complaint_type");
String subtype = request.getParameter("subtype");
String desc = request.getParameter("desc");
String status = "Unresolved";
if(desc.equals(null)||desc=="")
{
request.setAttribute("msg", "enter the description");
getServletContext().getRequestDispatcher("/complaint.jsp").forward(request, response);
}
else
{
ModelComplaint m = new ModelComplaint();
m.setUsername(username);
m.setName(name);
m.setComplaint_type(complaint_type);
m.setSubtype(subtype);
m.setDesc(desc);
m.setStatus(status);
int i=DaoComplaint.registerComplaint(m,sql);
if(i!=0)
{
System.out.println("value inserted");
}
else
{
System.out.println("value not inserted");
}
}//end of last else
}
}
DaoComplaint.java
package dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import model.ModelComplaint;
public class DaoComplaint {
private static Connection connect() {
Connection con=null;
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/park","root","aish");
System.out.println("connected");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
return con;
}
public static int registerComplaint(ModelComplaint m, String sql) {
int i=0;
Connection con=connect();
try {
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, m.getUsername());
ps.setString(2, m.getName());
ps.setString(3, m.getComplaint_type());
ps.setString(4, m.getSubtype());
ps.setString(5, m.getDesc());
ps.setString(6, m.getStatus());
i=ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} return i;
}
}
ModelComplaint.java
package model;
public class ModelComplaint
{
private String username;
private String name;
private String complaint_type;
private String subtype;
private String desc;
private String status;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getComplaint_type() {
return complaint_type;
}
public void setComplaint_type(String complaint_type) {
this.complaint_type = complaint_type;
}
public String getSubtype() {
return subtype;
}
public void setSubtype(String subtype) {
this.subtype = subtype;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}
Now going to the First page of the website if we choose New User then a Registration page opens up
for new users to register. Here also we are using Data Access Object and Model-View-Controller
Model for storing the information of new users to the database.
The data e tered here are sa ed to the ta le re rd i the data ase park . O pressi g the su it
button. This is the registration page for new students to register so that they can register the
complaints.
This registration page also uses the Dynamic Dropdown option for country state and city.
The are o e ted to the data ase ta les ou tr state a d it . Whi he er Cou tr e
select the state corresponding to that country on comes up in the state menu and hence whichever
state we choose the city corresponding to those state only comes up in the city.
A d all the fields that e e ter are for arded to Register“er let here the further processing for
saving the data in the database is done.
Register.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*" %>
<html>
<head>
<style type="text/css">
</style>
<title>Registration Page</title>
<meta charset="UTF-8">
<meta name="viewpoint" content="width=device-width, initial-
scale=1.0"> <script language="javascript" type="text/javascript">
var xmlHttp
var xmlHttp
function showState(str){
if (typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp==null){
alert("Browser does not support XMLHTTP Request")
return;
}
var url="state.jsp";
url +="?count=" +str;
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null); }
function stateChange(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ document.getElementById("state").innerHTML=xmlHttp.responseTe
xt }
}
function showCity(str){
if (typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp==null){
alert("Browser does not support XMLHTTP Request")
return;
}
var url="city.jsp";
url +="?count=" +str;
xmlHttp.onreadystatechange = stateChange1;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChange1(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ document.getElementById("city").innerHTML=xmlHttp.responseTe
xt }
}
</script>
</head>
<style>
body
{
background-
image:url("https://fi.ge.pgstatic.net/articles/processed/1453888104.ef9624e7c8b14fe7b967b011d6
8758dd.jpg");
background-repeat:no-repeat;
background-size:cover;
}
</style>
<center>
<h2><b><i><u>Registration page</u></i></b></h2>
<br>
${msg }
<br><br>
<form action="RegisterServlet" method="post">
<table>
<tr>
<td><b>Username:</b></td>
<td><input type="text" name="uname"></td>
</tr>
<tr>
<td><b>Password:</b></td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td><b>Re-Enter Password:</b></td>
<td><input type="password" name="rpass"></td>
</tr>
<tr>
<td><b>First Name:</b></td>
<td><input type="text" name="fname"></td>
</tr>
<tr>
<td><b>Last Name:</b></td>
<td><input type="text" name="lname"></td>
</tr>
<tr>
<td><b>Email:</b></td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td><b>Father's Name:</b></td>
<td><input type="text" name="father"></td>
</tr>
<tr>
<td><b>Enter Xth Marks</b></td>
<td><input type="text" name="xmarks"></td>
</tr>
<tr>
<td><b>Enter XII Marks</b></td>
<td><input type="text" name="xiimarks"></td>
</tr>
<tr>
<td><b>Enter your preferable Branch:</b></td>
<td><select name="branch">
<option>Mechanical</option>
<option>Computer Science</option>
<option>Electrical</option>
<option>Electronics</option>
<option>Information Technology</option>
<option>civil engineering</option>
</select></td>
</tr>
<tr>
<td><b>Gender:</b></td>
<td><select name="gender">
<option>Female</option>
<option>Male</option>
</select>
</td>
</tr>
<tr>
<td><b>Security Question:</b></td>
<td><select name="sques">
<option value="what is your pet name"> What is your pet name</option>
<option value="what is your last name">what is your last name</option>
<option value="what was your first school"> what was your first school</option>
</select>
</td>
</tr>
<tr>
<td><b>Answer:</b></td>
<td><input type="text" name="ans"></td>
</tr>
<tr>
<td><b>Phone:</b></td>
<td><input type="text" name="phone"></td>
</tr>
<tr>
<td><b>Country:</b></td>
<td><select name='country' onchange="showState(this.value)">
<option value="none">Select</option>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","aish");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from country");
while(rs.next()){
%>
<option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>
<%
}
%>
</select>
<br>
</td>
</tr>
<tr>
<td><b>State:</b></td>
<td>
<div id='state'>
<select name='state' >
<option value='-1'></option>
</select>
</div>
</td>
</tr>
<tr>
<td><b>City:</b></td>
<td>
<div id='city'>
<select name='city' >
<option value='-1'></option>
</select>
</div>
</td>
</tr>
<tr><td></td>
<td><input type="submit" name="Register" value="Register"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr></table>
</form>
</center>
</body>
</html>
We have Dynamic dropdown menus in this for Country City and State.
So,
State.jsp
<%@page import="java.sql.*"%>
<%
String country=request.getParameter("count");
String buffer="<select name='state' onchange='showCity(this.value);'><option value='-
1'>Select</option>";
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","aish");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from state where countryid='"+country+"'
"); while(rs.next()){
buffer=buffer+"<option value='"+rs.getString(1)+"'>"+rs.getString(3)+"</option>";
}
buffer=buffer+"</select>";
response.getWriter().println(buffer);
}
catch(Exception e){
System.out.println(e);
}
%>
City.jsp
<%@page import="java.sql.*"%>
<%
String state=request.getParameter("count");
String buffer="<select name='city'><option value='-1'>Select</option>";
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","aish");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("Select * from city where stateid='"+state+"' ");
while(rs.next()){
buffer=buffer+"<option value='"+rs.getString(2)+"'>"+rs.getString(3)+"</option>";
}
buffer=buffer+"</select>";
response.getWriter().println(buffer);
}
catch(Exception e){
System.out.println(e);
}
%>
RegisterServlet.java is a part of the Model View Controller model. Through this servlet we are putting
validations on the data being entered in the fields.
The validations are as follows:
1. All the required or necessary fields are not left empty.
2. The email entered is a valid email.
3. The passwords and the re-enter passwords fields are same.
4. The contact number is only digit.
RegisterServlet.java
package controller;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.DaoMVC;
import model.ModelMVC;
public class RegisterServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
// 1.retrieve all parameters from jsp page
String uname = request.getParameter("uname");
String pass = request.getParameter("pass");
String rpass = request.getParameter("rpass");
String fname = request.getParameter("fname");
String lname = request.getParameter("lname");
String email = request.getParameter("email");
String sques = request.getParameter("sques");
String ans = request.getParameter("ans");
String phone = request.getParameter("phone");
String country = request.getParameter("country");
String state = request.getParameter("state");
String father = request.getParameter("father");
String xmarks = request.getParameter("xmarks");
String xiimarks = request.getParameter("xiimaks");
String branch = request.getParameter("branch");
String gender = request.getParameter("gender");
if(uname.equals(null)||uname=="")
{
request.setAttribute("msg", "enter the username");
getServletContext().getRequestDispatcher("/Register.jsp").forward(request,
response);
}
else if(pass.equals(null)||pass=="")
{
request.setAttribute("msg", "enter a password");
getServletContext().getRequestDispatcher("/Register.jsp").forward(request,
response);
}
else if(rpass.equals(null)||rpass=="")
{
request.setAttribute("msg", "please re enter your password");
getServletContext().getRequestDispatcher("/Register.jsp").forward(request,
response);
}
else if(lname.equals(null)||lname=="")
{
request.setAttribute("msg", "enter your last name");
getServletContext().getRequestDispatcher("/Register.jsp").forward(request,
response);
}
else if(fname.equals(null)||fname=="")
{
request.setAttribute("msg", "enter your first name");
getServletContext().getRequestDispatcher("/Register.jsp").forward(request,
response);
}
else if(email.equals(null)||email=="")
{
request.setAttribute("msg", "enter the email");
getServletContext().getRequestDispatcher("/Register.jsp").forward(request,
response);
}
else if(ans.equals(null)||ans=="")
{
request.setAttribute("msg", "answer to the security question is required");
getServletContext().getRequestDispatcher("/Register.jsp").forward(request,
response);
}
else if(phone.equals(null)||phone=="")
{
request.setAttribute("msg", "enter a phone number");
getServletContext().getRequestDispatcher("/Register.jsp").forward(request,
response);
}
else if(!(pass.equals(rpass)))
{
request.setAttribute("msg", "Password does not match");
getServletContext().getRequestDispatcher("/Register.jsp").forward(request,
response);
}
else if(country.equals(null)||country=="")
{
request.setAttribute("msg","enter country name");
getServletContext().getRequestDispatcher("/Register.jsp").forward(request,
response);
}
else {
ModelMVC m = new ModelMVC();
m.setUname(uname);
m.setPass(pass);
m.setFname(fname);
m.setLname(lname);
m.setEmail(email);
m.setSques(sques);
m.setAns(ans);
m.setPhone(phone);
m.setCountry(country);
m.setState(state);
m.setFather(father);
m.setXmarks(xmarks);
m.setXiimarks(xiimarks);
m.setBranch(branch);
m.setGender(gender);
String sql="insert into recrd values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
int i=DaoMVC.registerUser(m,sql);
if(i!=0)
{
System.out.println("value inserted");
}
else
{
System.out.println("value not inserted");
}
}//end of last else
}
}
DaoMVC.java
package dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import model.ModelMVC;
public class DaoMVC {
private static Connection connect() {
Connection con=null;
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/park","root","aish");
System.out.println("connected");
} catch (ClassNotFoundException | SQLException e)
{ e.printStackTrace();
} return con;
}
public static int registerUser(ModelMVC m, String sql)
{ int i=0;
Connection con=connect();
try {
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, m.getUname());
ps.setString(2, m.getPass());
ps.setString(3, m.getFname());
ps.setString(4, m.getLname());
ps.setString(5, m.getEmail());
ps.setString(6, m.getSques());
ps.setString(7, m.getAns());
ps.setString(8, m.getPhone());
ps.setString(9, m.getCountry());
ps.setString(10, m.getState());
ps.setString(11, m.getFather());
ps.setString(12, m.getXmarks());
ps.setString(13, m.getXiimarks());
ps.setString(14, m.getBranch());
ps.setString(15, m.getGender());
i=ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} return i;
}
}
ModelMVC.java
package model;
public class ModelMVC
{
private String uname;
private String pass;
private String fname;
private String lname;
private String email;
private String sques;
private String ans;
private String phone;
private String country;
private String state;
private String father;
private String xmarks;
private String xiimarks;
private String branch;
private String gender;
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
Now if from the first page we select the admin option then the admin login page opens up. Which is
also connected to another admin table having login information for the admins.
Admins are the ones which handle this website they would handle all the complaints. On successful
log in as admin then the complaint table opens up which has the list of all the complaints whose
“tatus is U resol ed . No the ad i a resol e a o plai t the ish hoosi g the
Resol e optio orrespo di g to ea h o plai t i the complaint table. And as we choose the
o plai t optio et o plai t resol e page ope s up.
Ad i logi .jsp page has the page i hi h e ha e to e ter the user a e a d pass ord. And the
e tered data i for arded to ad i .jsp here the data is ross checked.
Adminlogin.jsp
Ad i .jsp is the page hi h is o e ted to the data ase ta le ad i i the data ase park . The
entered username and password are checked with the data present in the database entries of the
table admin if they match then the login is successfully done and is forwarded to the next page
o plai .jsp hi h has o plai t ta le ha i g all the data of the o plai ts registered the
students.
If the data e tered does ot at h the data i the data ase the sorr re ord ot fou d essage
pops up.
Admin.jsp
<%@ page import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
</head>
<body>
<%! String userdbName;
String userdbPsw;
String dbUsertype;
%>
<%
Connection con= null;
PreparedStatement ps = null;
ResultSet rs = null;
String driverName = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/park";
String user = "root";
String dbpsw = "aish";
String sql = "select * from admin where name=? and
password=?"; String name = request.getParameter("name");
String password = request.getParameter("password");
if((!(name.equals(null) || name.equals("")) && !(password.equals(null) ||
password.equals(""))) )
{
try{
Class.forName(driverName);
con = DriverManager.getConnection(url, user, dbpsw);
ps = con.prepareStatement(sql);
ps.setString(1, name);
ps.setString(2, password);
rs = ps.executeQuery();
if(rs.next())
{
userdbName = rs.getString("name");
userdbPsw = rs.getString("password");
if(name.equals(userdbName) && password.equals(userdbPsw))
{ session.setAttribute("name",userdbName);
response.sendRedirect("complain.jsp"); } }
else
response.sendRedirect("error.jsp");
rs.close();
ps.close(); }
catch(SQLException sqe) {
out.println(sqe); }
}
else {
%>
<center><p style="color:red">Error In Login</p></center>
<%
getServletContext().getRequestDispatcher("/adminlogin.jsp").include(request,
response);
}
%>
</body>
</html>
If you are successfully logged in then the Complaint page opens up which have information about
all the complaints that are Unresolved along with the resolve button for the admin to know the
complaint in detail and to resol e the ou are for arded to Resol e.jsp . The data i the Co
plai t ta le o es fro the data ase ta le Co plai t fro data ase park .
Complain.jsp
<%@ page import="java.sql.*" %>
<html>
<head>
<style type="text/css">
</style>
<script>
</script>
<title>Home</title>
<meta charset="UTF-8">
<meta name="viewpoint" content="width=device-width, initial-scale=1.0">
</head>
<style>
body
{
background-image:url("https://cdn-
az.allevents.in/banners/3d8506690dfe21619ba45a01c826a60a");
background-repeat:no-repeat;
background-size:cover;
}
</style> <%
Class.forName ("com.mysql.jdbc.Driver");
Connection conn=null;
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/park","root","aish");
Statement stm = conn.createStatement();
String s = "SELECT * FROM complaint where
Status='Unresolved'"; ResultSet r = stm.executeQuery(s); %>
<body>
<center>
<h1>COMPLAINT TABLE</h1><TABLE BORDER="1">
<TR>
<TH>COMPLAINT ID</TH>
<TH>USERNAME</TH>
<TH>COMPLAINT NAME</TH>
<TH>STATUS</TH>
<TH>RESOLVE</TH>
</TR>
<% while(r.next()){ %>
<TR>
<TD> <%= r.getString(1) %></td>
<TD> <%= r.getString(2) %></TD>
<TD> <%= r.getString(3) %></TD>
<TD> <%= r.getString(7) %></TD>
<TD> <a href="Resolve.jsp?id=<%=r.getString(1) %>">Resolve</a> </TD>
</TR>
<%}%>
</TABLE>
</center>
</body>
</html>
Now whichever Complaint we want to resolve we click on the resolve button corresponding to that
complaint.
A new complaint resolve page opens up. The code of that page is as follows and the remark which
the admin posts is saved and Status of the complaint is switched from Unresolved to Resolved.
And then it is redirected to the complaints page.
Resolve.jsp
<%@ page import="java.sql.*" %>
<html>
<head>
<style type="text/css">
</style>
<script>
</script>
<title>Home</title>
<meta charset="UTF-8">
<meta name="viewpoint" content="width=device-width, initial-scale=1.0">
</head>
<style>
body
{
background-image:url("http://coer.ac.in/images/adm.jpg");
background-repeat:no-repeat;
background-size:cover;
}
</style>
<%
String id=request.getParameter("id");
Class.forName ("com.mysql.jdbc.Driver");
Connection conn=null;
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/park","root","aish");
Statement stm = conn.createStatement();
String s = "SELECT * FROM complaint where Complaint_id='"+id+"'";
ResultSet r = stm.executeQuery(s); r.next();
%>
<center>
<h2><u><i><b>Resolve Complaint Page</b></i></u></h2>
<TABLE BORDER="1">
<TR>
<TH><b>Complaint ID:</b></TH>
<TH> <%=r.getString(1) %></TH> </TR>
<TR>
<TH><b>UserName:</b></TH>
<Th><%= r.getString(2) %></Th>
</TR>
<tr>
<TH><b>Complaint Name:</b></TH>
<th><%= r.getString(3) %></th>
</tr>
<tr>
<TH><b>Complaint Type:</b></TH>
<th><%= r.getString(4) %></th>
</tr>
<tr>
<TH><b>Complaint Sub-Type:</b></TH>
<th><%= r.getString(5) %></th></tr>
<TR>
<TH><b>Complaint Description:</b></TH>
<TH><%=r.getString(6) %></TH></TR>
<TR>
<TH><b>Remark</b></TH>
<TH><textarea rows="8" cols="40" name="remark">
</textarea>
</TH></TR>
<TR>
<TH></TH>
<TH><input type="submit" name="Submit"
value="Submit"/></TH> </TR>
</TABLE>
</center>
<%
String remark = request.getParameter("remark");
String queryString = " INSERT INTO complaint (Remark)" + "VALUES(?)
where Complaint_id='"+id+"'";
String query="UPDATE complaint SET status='Resolved' where Complaint_id='"+id+"'";
PreparedStatement pstatement = null;
PreparedStatement ps = null;
pstatement = conn.prepareStatement(queryString);
pstatement.setString(1, remark);
ps = conn.prepareStatement(query);
ps.executeUpdate();
%>
</body>
</html>
WORKING MODEL OF THE PROJECT
O pressi g the “u it utto the data e tered are sa ed to ta le Co plai t i data ase park
If you select the New user option then the Registration pages opens up:
Registration page opens up and here we have to enter all the required option. If we do not enter the
required information then the validation message comes up and the registration becomes
unsuccessful.
O li ki g the the Register optio then through Model View Controller the data entered is saved to
ta le re rd i the data ase park .
Complain.jsp contains all the data of the U resol ed o plai ts fro ta le o plai t fro data ase park a d o sele ti g
the Resol e optio orrespo di g to the o plai t the page Resol e.jsp ope s up.
Clicking the resolve button corresponding to the complaint that Complaint resolve page opens up:
Resolve.jsp helps the admin to resolve the complaint. The complaint which we want to resolve all the
information in detail to that complain comes up and then the admin posts the remark for the complaint. And
then the status of the co plai t is s it hed fro U resol ed to Resol ed