Lab Manual
Lab Manual
ASSIGNMENT NO: 1
Title of Assignment:Case study.
Problem Statement: students should visit different websites (Min. 5) for the different client projects and
note down the evaluation results for these websites, either good website or bad website
Objectives: From the evaluation, students should learn and conclude different website design issues, which
should be considered while developing a website.
1. An easy-to-update CMS:One of the first problems people run into is that it’s difficult to update
their website. Either they’re unable to do it themselves or they’ve hired out website management
and maintenance, which is fine, except that when a change is needed it sometimes takes a
considerable amount of time for it to actually happen. There are a number of intuitive, easy-to-use
and update Content Management Systems (CMS) that are customizable and widely known to
developers, like WordPress, Joomla, Drupal, Expression Engine and many others.
2. Responsive design: A responsive website is a website designed to change its look based on the
device it’s viewed on. For instance, if a customer views your website on their desktop, and then
switches to their phone, the site won’t just appear desktop-sized on the smaller screen – that would
look cramped and chaotic. A responsive design simplifies your site and makes it easy to read on a
smaller device. This component of a website is critical because more and more people browse the
internet, shop and socialize on their phones and tablets, and your website must allow them to easily
switch devices without losing them.
3. Helpful navigation: Once your visitors get to your website, they should be able to find where they
want to go within seconds. A drop-down navigation bar at the top of your site is a common and
very simple way to organize the pages and links on your website. Plan out your site map in a logical
way, then make sure that each link goes to the appropriate page. Broken links or links that misdirect
visitors will cause them to lose interest in your site or become frustrated and ultimately leave.
4. Strong brand identity: Before you begin a site redesign, think carefully about how you want your
brand portrayed. Consider color scheme, font, the type of graphics and photos, how much content
and empty space you’ll use, the tone of voice and message of your brand… All of these things go
into creating a cohesive identity that will subtly inform your visitor of who you are and what you do.
A confused brand identity will leave your visitors unsure of and unable to relate to your company.
5. High-quality content: Every page on your website should have well-written, keyword-rich content.
Search engines crawl sites looking for content that is readable, valuable and updated often and then
serve those sites up higher in results than those that don’t. So whatever page – be it service listings,
pricing, history, testimonials – make sure that you have engaging, useful and informative content on
it.
6. A blog: As mentioned earlier, search engines favor sites with high-quality content that’s updated
regularly. The very best way to ensure your site has this key feature is to start a business blog. To
make search engines happy, post on a regular basis, keeping your website updated with fresh
content, and post informative content that positions your business as a thought leader – that’s some
high-quality stuff!
7. Clear calls-to-action: Being clear about what you want your site visitors to do helps direct them
and alleviate confusion. Throughout your site, be specific – whether you want them to subscribe to
your blog, fill in a contact form, download content, etc. Use powerful, active and urgent language
(Buy/Donate/Register/Subscribe/Download Now!) and position a call-to-action on every page
above the fold.
8. Contact information: Have your business’s address, phone number and email listed in a footer that
appears on every page – that way no matter where your visitors go on your site, they’ll know how
to get a hold of you. You can also create a “Contact Us” page in addition to your footer, making it
obvious that you value feedback, questions and customer interaction.
9. Social media buttons: A website without the support of social media is missing a huge opportunity
to connect with potential customers. Almost everyone who uses the Internet also has a social media
profile on some network. So include links to your business’s social profiles and add “share” buttons
to your content. If you haven’t already, consider creating business pages on Twitter, Facebook,
LinkedIn, Google+, YouTube and Pinterest.
10. Security features: This is something that’s most important to websites where visitors may enter
credit card or other sensitive information. Chances are your site is secure, but visitors will trust you
even more when you install further security features on your site and show them through a graphic
that says “secured by…” Even if you don’t sell things through your website, let people know that
any information they provide (name, email, address, etc.) to download content or subscribe to a
newsletter or blog is safe with you and that you won’t sell it or use it for other than the intended
purpose.
Here are some of the major issues faced by web designers while building a responsive website:
When compared to a desktop site, building a responsive website takes a significant amount of time.
In responsive websites, the content should be prioritized for mobile use. For smaller screens, the
designer must know precisely what matters, the devices that people use, their circumstances, and
their unique goals.
Interactions in desktop sites and mobile devices are different.
Responsive websites recognize media queries to assess the screen size of every visitor and then
display the layout accurately. The issue here is that old browsers, particularly Internet Explorer
version 8 and older, do not recognize media queries.
In responsive design, scaled images instantly lose details, and hence their meaning. This is because
scaling mainly happens depending on the size of the screen and not on context.
On smaller devices, designing intuitive navigation menus becomes a real a challenge due to the
limited screen size.
Conclusion:-
ASSIGNMENT NO: 2
Title of Assignment:
Designawebpageindex.htmforanyclientwebsite.
Problem Statement:Implementawebpageindex.htmforanyclientwebsite.
a. HTMLsyntax:headingtags,basictagsandattributes,frames,tables,images,lists,linksfortext andimages,
forms etc.
b. UseofInternal CSS,Inline CSS,External CSS.
c. Use at least 2 pages on your website
Theory:HTML is an acronym which stands for Hyper Text Markup Language which is used for
creating web pages and web applications. Let's see what is meant by Hypertext Markup Language, and
Web page.
Hyper Text: Hypertext simply means "Text within Text." A text has a link within it, is a hypertext.
Whenever you click on a link which brings you to a new webpage, you have clicked on a hypertext.
Hypertext is a way to link two or more web pages (HTML documents) with each other.
Markup language: A markup language is a computer language that is used to apply layout and
formatting conventions to a text document. Markup language makes text more interactive and dynamic.
It can turn text into images, tables, links, etc.
Web Page: A web page is a document which is commonly written in HTML and translated by a web
browser. A web page can be identified by entering an URL. A Web page can be of the static or
dynamic type. With the help of HTML only, we can create static web pages.
HTML is a markup language which is used for creating attractive web pages with the help of styling,
and which looks in a nice format on a web browser. An HTML document is made of many HTML tags
and each HTML tag contains different content.
1. <!DOCTYPE>
2. <html>
3. <head>
4. <title>Web page title</title>
5. </head>
6. <body>
7. <h1>Write Your First Heading</h1>
8. <p>Write Your First Paragraph.</p>
9. </body>
10. </html>
HTML Tags are like keywords which define that how web browser will format and display the
content. With the help of tags, a web browser can distinguish between an HTML content and a simple
content. When a web browser reads an HTML document, browser reads it from top to bottom and left
to right. HTML tags are used to create HTML documents and render their properties. Each HTML
tags have different properties.
HTML Attribute: HTML attributes are special words which provide additional information about the
elements or attributes are the modifier of the HTML element.Each element or tag can have attributes,
which defines the behavior of that element.The Attribute should always be applied with its name and
value pair.
A HTML heading or HTML h tag can be defined as a title or a subtitle which you want to
display on the webpage. When you place the text within the heading tags <h1>.........</h1>. It is
displayed on the browser in the bold format and size of the text depends on the number of
heading. There are six different HTML headings which are defined with the <h1> to <h6> tags,
from highest level h1 (main heading) to the least level h6 (least important heading).
The HTML anchor tag defines a hyperlink that links one page to another page. It can create
hyperlink to other web page as well as files, location, or any URL. The "href" attribute is the
most important attribute of the HTML a tag. This links to destination page or URL. The href
attribute is used to define the address of the file to be linked. In other words, it points out the
destination page.
The syntax of HTML anchor tag is given below. <a href = "..........."> Link Text
</a><a href="https://www.google.com/"> this-link </a>
Style attributes setting the style of an HTML element, can be done with the style attribute. The
HTML style attribute has the syntax :<tagname style="property:value;">
HTML Formatting Elements were designed to display special types of text:
<b> - Bold text
<strong> - Important text
<i> - Italic text
<em> - Emphasized text
<mark> - Marked text
<small> - Smaller text
<del> - Deleted text
<ins> - Inserted text
<sub> - Subscript text
<sup> - Superscript text
You can add comments to your HTML source by using the following syntax:
<!-- This is a comment -->
<p>This is a paragraph.</p>
Inline CSS: - An inline CSS is used to apply a unique style to a single HTML element.
An inline CSS uses the style attribute of an HTML element.
The following example sets the text color of the <h1> element to blue, and the text color of
the <p> element to red:
<h1 style="color:blue;">A Blue Heading</h1>
<p style="color:red;">A red paragraph.</p>
Internal CSS:-An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the <head> section of an HTML page, within a <style> element.
The following example sets the text color of ALL the <h1> elements (on that page) to blue, and the text
color of ALL the <p> elements to red. In addition, the page will be displayed with a "powderblue"
background color:
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
External CSS:-An external style sheet is used to define the style for many HTML pages.
To use an external style sheet, add a link to it in the <head> section of each HTML page:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Conclusion:
ASSIGNMENT NO: 3
Title of Assignment:
XML,DTD and CSS/XSL.
Problem Statement: Design the XML document to store the information of the employees of any business
organization and demonstrate the use of:
a) DTD
b) XML Schema
And display the content in (e.g., tabular format) by using CSS/XSL.
There are three important characteristics of XML that make it useful in a variety of systems and
Solutions:
1. XML is extensible − XML allows you to create your own self-descriptive tags, or language, that
suits your application.
2. XML carries the data, does not present it − XML allows you to store the data irrespective of
how it will be presented.
3. XML is a public standard − XML was developed by an organization called the World Wide
Web Consortium (W3C) and is available as an open standard.
Tools and Technology:-The XML document have an XML declaration, but it is optional, and it is
written as−<? xml version = "1.0" encoding = "UTF-8"?>
Where version is nothing but the version of an XML document and UTF specifies thecharacter-
encoding used in the document. Each XML-element needs to be closed eitherwith start or with end
elements −<element>.........</element>
An XML document can have only one root element.
XML Attributes:
Using a name/value pair, an attribute specifies a single property for an element. AnXML- element
can have one or more attributes. For example −
<a href = "http://www.google.com/">XMLTutorial</a>
Here href is the attribute name and http://www.google.com/ is attribute value.
DTD:- What is a DTD?
DTD stands for Document Type Definition.
The purpose of a DTD is to define the structure and the legal elements and attributes of an XML
document:
When to Use a DTD?
With a DTD, independent groups of people can agree to use a standard DTD for interchanging data.
With a DTD, you can verify that the data you receive from the outside world is valid.
You can also use a DTD to verify your own data.
When NOT to Use a DTD?
XML does not require a DTD.
When you are experimenting with XML, or when you are working with small XML files, creating
DTDs may be a waste of time.
If you develop applications, wait until the specification is stable before you add a DTD. Otherwise,
your software might stop working because of validation errors.
XML Schema: An XML Schema describes the structure of an XML document, just like a DTD.
An XML document with correct syntax is called "Well Formed".
An XML document validated against an XML Schema is both "Well Formed" and "Valid".
HTML XML
1. It was written in 1993. It was released in 1996.
2. HTML stands for Hyper Text Markup XML stands for Extensible Markup Language.
Language.
3. HTML is static in nature. XML is dynamic in nature.
4. It was developed by WHATWG. It was developed by Worldwide Web
Consortium.
5. It is termed as a presentation language. It is neither termed as a presentation nor a
programming language.
6. HTML is a markup language. XML provides a framework to define markup
languages.
7. HTML can ignore small errors. XML does not allow errors.
8. It has an extension of .html and .htm It has an extension of .xml
9. HTML is not Case sensitive. XML is Case sensitive.
10. HTML tags are predefined tags. XML tags are user-defined tags.
11. There are limited numbers of tags in XML tags are extensible.
HTML.
12. HTML does not preserve white spaces. White space can be preserved in XML.
13. HTML tags are used for displaying the XML tags are used for describing the data not
data. for displaying.
14. In HTML, closing tags are not necessary. In XML, closing tags are necessary.
15. HTML is used to display the data. XML is used to store data.
16. HTML does not carry data it just displays XML carries the data to and from the database.
it.
17. HTML offers native object support. IN XML, the objects are expressed by
conventions using attributes.
18. HTML document size is relatively small. XML document size is relatively large as the
approach of formatting and the codes both are
lengthy.
19. An additional application is not required DOM(Document Object Model) is required for
for parsing of JavaScript code into the parsing JavaScript codes and mapping of text.
20. Some of the tools used for HTML are: Some of the tools used for XML are:
Visual Studio Code
Oxygen XML
How DTD Works in XML?
DTD is also the schema language preferred in markup language. The general Syntax is given below:
<!DOCTYPE root element name
[
declaration1
declaration2
<!ELEMENT><ATTLIST><!ENTITY><!NOTATION>
]>
In the above syntax, the DTD name is the root element name and followed by options which say about the
schemas and types. The keyword! DOCTYPE should be uppercase. Let’s see Element declarations.
The working of DTD is performed by the following steps:
First, create a DTD file for the respective XML Document.
Next outline the structure of the document.
Initiate with the root node which is the same as DOCTYPE. You can create DTD either internal or
external references.
Include all the elements, attributes, entities for the file. The parser eliminates empty elements.
Element Declarations:-The element specifications with the sequence of its elements are stated as
<!ELEMENT name (seq of elements)> Also, the element specifies the number of occurrences of the child
elements using (+, *,? ).
+ sign indicates two or more frequency, *indicates the element can appear more number of times.
? Indicates elements can occur only once.
The following declaration is <!ELEMENT pizza (onion? Cheese*((veg|noveg) + |topping))>
The above statement implies that the pizza element can have one onion elements followed by one or
more cheese and so on.
<pizza>
<onion> fried </onion>
<cheese> thin </cheese>
<cheese> thick </cheese>
<topping>oregano </topping>
</pizza>
Attribute Declarations
The attributes for a given element is designed by the following rule:
<!ATTLIST element name attribute names 1 attribute type restriction/Default >
here attribute is specified using the keyword ATTLIST, the element name is included for the
respective attributes unless they are optional. The attribute types include PCDATA, tokens, entity,
notation. Last is restriction/default they are placed based on the occurrences of the values. The
attribute default includes #IMPLIED, #REQUIRED, #FIXED. The implied specifies the attribute
value doesn’t appear and required implies the attribute value is present and fixed denotes a constant
value.
Defining Entities
Entity is used to specify special characters. The entity declaration is
<!ENTITY entity_name SYSTEM "URL path">
Ex:
<!ENTITY SYSTEM "http://www. ckjd.com/pot.dtd">
As DTD is model of the XML document it talks about the elements, attributes being used which are
essential and optional as they are easy to validate the document and there are two types of DTDs
namely,
Internal DTD
External DTD
Conclusion:-
ASSIGNMENT NO: 4
T.E. Computer Engineering AY 2023-24 Semester-II Page 10
WTL Lab (2019 Course)
Problem Statement:
DesignandimplementasimplecalculatorusingJavaScriptforoperationslikeaddition,multiplication,subtraction,
division, square of number etc.
1. Design calculator interface like text field for input and output, buttons for numbers and operators etc.
2. Validate input values
3. Prompt/alerts for invalid values etc.
Objectives: Learn how to validate input in java script.Working with alert massage.
JavaScript helps the users to build modern web applications to interact directly without reloading the page
every time. JavaScript is commonly used to dynamically modify HTML and CSS to update a user interface
by the DOM API. It is mainly used in web applications.
Use of JavaScript.
o Client-side validation.
o Displaying date and time.
o To validate the user input before submission of the form.
o Open and close new windows.
o To display dialog boxes and pop-up windows.
o To change the appearance of HTML documents.
o To create the forms that respond to user input without accessing the server.
4. Java is a strongly typed language, JavaScript is a loosely typed language, which means
which means that the user has to decide that the user does not have to worry about the data-
the data type of the variable before type of the variable before and after the declaration.
declaring and using it. Example "var a", the "a" variable can store the value
Example "int a", the variable "a" can of any data-type.
store the value of integer type only.
5. Java program should be compiled JavaScript needs to be integrated into the HTML
before execution. program for the execution.
6. The web-browser is not required to run The web-browser is essential to run the JavaScript
java programs. programs.
9. It requires a large amount of memory. It does not require that amount of memory.
10. Java programming language was JavaScript programming language was developed by
developed by the "Sun Microsystems." the "Netscape."
11. In Java programming language, On the other hand, programs in JavaScript are saved
programs are saved with the ".java" with the ".js" extension.
extension.
12. Java is stored on the host machine as JavaScript is stored on the Host machine (client
the "Byte" code. Machine) as the "source" text.
Validation:
When a client enters all the necessary data and presses the submit button, form
validation is done at server side If data entered by a client is incorrect or missing, the server
needs to send all data back to the client and request for resubmission of form with correct
information. This is really a lengthy process which puts a lot of load(burden) on the server.
So, JavaScript provides a way to validate form's data on the client's side itself before sending
it to the web server. Form validation performs two functions-
o Basic Validation –First of all the form must be checked to make sure all the mandatory
fields are filled in. It would require just a loop through each field in the form and
check for the data.
o Data Format Validation − Secondly, the data that is entered must be checked for
correctFormat and its value. The code must include appropriate logic to test correctness of
data.
Following steps are used to Create and Execute web applications,
The alert () method in JavaScript is used to display a virtual alert box. It is mostly used to give a warning
message to the users. It displays an alert dialog box that consists of some specified message (which is
optional) and an OK button. When the dialog box pops up, we have to click "OK" to proceed.
The alert dialog box takes the focus and forces the user to read the specified message. So, we should avoid
overusing this method because it stops the user from accessing the other parts of the webpage until the box
is closed.
We can understand the usefulness of the alert method using an example. Suppose we have to fill a form for
an identity card. It asks about the date of birth for the eligibility criteria of the identity card. If the age is 18
years or above, then the process will continue. Otherwise, it will show a warning message that the age is
below 18 years. This warning message is the 'Alert Box'.
Another example is suppose a user is required to fill the form in which some mandatory fields are required
to enter some text, but the user forgets to provide the input. As the part of the validation, we can use the
alert dialog box to show a warning message related to fill the textfield.
<html>
<head> <script type = "text/javascript">
function fun() {
alert (" Hello World \n Welcome to the javaTpoint.com \n This is an alert dialog box ");
}
</script> </head>
<body>
<p> Click the following button to see the effect </p>
<form>
<input type = "button" value = "Click me" onclick = "fun();" />
</form>
</body>
</html>
JavaScript is used in several ways in web pages such as generate warning messages, build image galleries,
DOM manipulation, form validation, and more. Method to add JavaScript.
1. Embedding code
2. Inline code
3. External file
I. Embedding code:-
To add the JavaScript code into the HTML pages, we can use the <script>.....</script> tag of the HTML
that wrap around JavaScript code inside the HTML program. Users can also define JavaScript code in
the <body> tag (or we can say body section) or <head> tag because it completely depends on the structure
of the web page that the users use.
<!DOCTYPE html >
<html>
<head>
<title> page title</title>
<script>
document.write("Welcome to Javatpoint");
</script>
</head>
<body>
<p>Inthis example we saw how to add JavaScript in the head section </p>
</body>
</html>
Output:-
II. Inline code:-Generally, this method is used when we have to call a function in the HTML event
attributes. There are many cases (or events) in which we have to add JavaScript code directly eg., OnMover
event, OnClick, etc.
III. External file:- We can also create a separate file to hold the code of JavaScript with the (.js) extension
and later incorporate/include it into our HTML document using the src attribute of the <script> tag. It
becomes very helpful if we want to use the same code in multiple HTML documents. It also saves us from
the task of writing the same code over and over again and makes it easier to maintain web pages.
<html>
<head>
<meta charset="utf-8">
<title>Including a External JavaScript File</title>
</head>
<body>
<form>
<input type="button" value="Result" onclick="display()"/>
</form>
<script src="hello.js">
</script>
</body>
</html>
//!---Hello.js
function display() {
alert("Hello World!");
Output:-
Conclusion:
ASSIGNMENT NO: 5
Title of Assignment:ImplementthesampleprogramdemonstratingtheuseofServlet.
Objectives:
Software Needed:
1. Any Operating System
2. JDK 7or later
3. Editors:Netbeans/Eclipse
4. Web browser
5. Tomcat 7 or later
Theory:
Servlet: What is Servlet?
1. Loading a Servlet: The first stage of the Servlet lifecycle involves loading and initializing the
Servlet by the Servlet container. The Web container or Servlet Container can load the Servlet
at either of the following two stages :
Initializing the context, on configuring the Servlet with a zero or positive integer value.
If the Servlet is not preceding stage, it may delay the loading process until the Web container
determines that this Servlet is needed to service a request.
The Servlet container performs two operations in this stage :
a. Loading : Loads the Servlet class.
b. Instantiation : Creates an instance of the Servlet. To create a new instance of the
Servlet, the container uses the no-argument constructor.
2. Initializing a Servlet: After the Servlet is instantiated successfully, the Servlet container
initializes the instantiated Servlet object. The container initializes the Servlet object by
invoking the Servlet.init(ServletConfig) method which accepts ServletConfig object reference
as parameter.
The Servlet container invokes the Servlet.init(ServletConfig) method only once, immediately
after the Servlet.init(ServletConfig) object is instantiated successfully. This method is used to
initialize the resources, such as JDBC datasource.
Now, if the Servlet fails to initialize, then it informs the Servlet container by throwing
the ServletException or UnavailableException.
3. Handling request: After initialization, the Servlet instance is ready to serve the client requests.
The Servlet container performs the following operations when the Servlet instance is located
to service a request :
Servlet Advantage
1. Servlets provide a way to generate dynamic documents that is both easier to write and faster to run.
2. provide all the powerfull features of JAVA, such as Exception handling and garbage collection.
3. Servlet enables easy portability across Web Servers.
4. Servlet can communicate with different servlet and servers.
5. Since all web applications are stateless protocol, servlet uses its own API to maintain session
Servlet Disadvantage
1. Designing in servlet is difficult and slows down the application.
2. Writing complex business logic makes the application difficult to understand.
3. You need a Java Runtime Environment on the server to run servlets. CGI is a completely language
independent protocol, so you can write CGIs in whatever languages you have available (including Java
if you want to).
Technology/Tool In Brief
1. JSP and Servlets
2. IDE: NetBeans 7.0 or Later
3. Databases: MySQL
NetBeans: NetBeans is an IDE, used for quickly and easily developing java desktop, mobile,and web
applications, as well as HTML5 applications with HTML, JavaScript, and CSS. Also provides a 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 freely available open source Relational Database Management System(RDBMS). It
uses the Structured Query Language (SQL).
SQL is the most popular language for adding, accessing and managing data in a database. It is most noted
for its quick processing, proven reliability, ease and flexibility of use. MySQL is an essential part of almost
every open source PHP application. Good examples for PHP & MySQL-based scripts are WordPress,
Joomla, Magento and Drupal.
Conclusion:
ASSIGNMENT NO: 6
Title of Assignment:Implement theprogramdemonstratingtheuseofJSP.
Problem Statement: Create a database table students_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.
Software Needed:
1. Any Operating System
2. JDK 7or later
3. Editors: Netbeans/Eclipse
4. Web browser
5. Tomcat 7 or later
Theory:
Java Server Pages (JSP): It is a server side programming technology that is used to createdynamic 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.
Why we need JSP?
JSP is used for the design of dynamic web page and servlet is used to code the logic that is present i.e. in
the MVC (Model-View-Controller) architecture, the servlet is the controller and the JSP is the view.
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.
a server. Although servlets can respond to any types of requests, they most commonly execute applications
hosted on Web servers.
NetBeans: NetBeans is an IDE, used for quickly and easily developing java desktop, mobile,and web
applications, as well as HTML5 applications with HTML, JavaScript, and CSS. Also provides a 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 freely available open source Relational Database Management System(RDBMS). It
uses the Structured Query Language (SQL).
SQL is the most popular language for adding, accessing and managing data in a database. It is most noted
for its quick processing, proven reliability, ease and flexibility of use. MySQL is an essential part of almost
every open source PHP application. Good examples for PHP & MySQL-based scripts are WordPress,
Joomla, Magento and Drupal.
Design / Execution Steps
Following steps are used to Create and Execute web applications,
1. Design html and jsp files with an extension of.html and .jsp
2. Write database connection page using servlet
3. Set MySQL username, password and database name in database connection page
4. Start the Tomcat Server with port number
5. Open the browser and type localhost:8084
Test Cases
Manual testing is used to validate the fields like username, password, mobile number and email id’s of
the users entered by user with the database.
Conclusion:
ASSIGNMENT NO: 7
Title of Assignment:Buildadynamic webapplication usingPHPand MySQL.
Objectives:
Theory:
What is PHP?
PHP is an acronym for "PHP: Hypertext Preprocessor"
PHP is a widely-used, open source scripting language
PHP scripts are executed on the server
PHP is free to download and use
<!DOCTYPE html>
<html><body>
<?php
$x = "Hello world!";
$y = 'Hello world!';
$x = 5985;
$cars = array("Volvo","BMW","Toyota");
echo $x;
echo "<br>";
echo $y;
echo "<br>";
echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";
?>
</body></html>
With PHP you are not limited to output HTML. You can output images or PDF files. You can also output
any text, such as XHTML and XML.
Creating a Database
To create and delete a database you should have admin privilege. Its very easy to create a new MySQL
database. PHP uses mysql_query function to create a MySQL database. This function takes two
parameters and returns TRUE on success or FALSE on failure.
Syntax: bool mysql_query( sql, connection );
Sr.No Parameter & Description
1 Sql
Required - SQL query to create a database
2 Connection
Optional - if not specified then last opend connection by mysql_connect will be used.
Example
Try out following example to create a database −
<?php
$dbhost='localhost:3036';
$dbuser='root';
$dbpass='rootpassword';
$conn =mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ){
die('Could not connect: '.mysql_error());
}
if(! $retval){
die('Could not create database: '.mysql_error());
}
Selecting a Database
Once you establish a connection with a database server then it is required to select a particular database
where your all the tables are associated.
This is required because there may be multiple databases residing on a single server and you can do work
with a single database at a time.
PHP provides function mysql_select_db to select a database.It returns TRUE on success or FALSE on
failure.
Syntax: bool mysql_select_db( db_name, connection );
Sr.No Parameter & Description
1 db_name
Required - Database name to be selected
2 Connection
Optional - if not specified then last opend connection by mysql_connect will be used.
Example
Here is the example showing you how to select a database.
<?php
$dbhost='localhost:3036';
$dbuser='guest';
$dbpass='guest123';
$conn =mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ){
die('Could not connect: '.mysql_error());
}
mysql_select_db('test_db');
mysql_close($conn);
?>
$dbhost='localhost:3036';
$dbuser='root';
$dbpass='rootpassword';
$conn =mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ){
die('Could not connect: '.mysql_error());
}
if(! $retval){
die('Could not create table: '.mysql_error());
}
mysql_close($conn);
?>
In case you need to create many tables then its better to create a text file first and put all the SQL
commands in that text file and then load that file into $sql variable and excute those commands.
Consider the following content in sql_query.txt file
CREATE TABLE employee(
emp_id INT NOT NULL AUTO_INCREMENT,
emp_nameVARCHAR(20) NOT NULL,
emp_address VARCHAR(20) NOT NULL,
emp_salary INT NOT NULL,
join_datetimestamp(14) NOT NULL,
primary key ( emp_id ));
<?php
$dbhost='localhost:3036';
$dbuser='root';
$dbpass='rootpassword';
$conn =mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ){
die('Could not connect: '.mysql_error());
}
$query_file='sql_query.txt';
$fp=fopen($query_file,'r');
$sql=fread($fp,filesize($query_file));
fclose($fp);
mysql_select_db('test_db');
if(! $retval){
die('Could not create table: '.mysql_error());
}
What is CRUD
CRUD is an acronym for Create, Read, Update, and Delete. CRUD operations are basic data manipulation
for database. We've already learned how to perform create (i.e. insert), read (i.e. select), update and delete
operations in previous chapters. In this tutorial we'll create a simple PHP application to perform all these
operations on a MySQL database table at one place.
Creating the Database Table:-Execute the following SQL query to create a table named employees inside
your MySQL database. We will use this table for all of our future operations.
CREATETABLE employees (
id INTNOTNULLPRIMARYKEYAUTO_INCREMENT,
name VARCHAR(100)NOTNULL,
address VARCHAR(255)NOTNULL,
salary INT(10)NOTNULL
);
Creating the Landing Page:-First we will create a landing page for our CRUD application that contains a
data grid showing the records from the employees database table. It also has action icons for each record
displayed in the grid that you may choose to view its details, update it, or delete it.
We'll also add a create button on the top of the data grid that can be used for creating new records in
the employees table. Create a file named "index.php" and put the following code in it:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dashboard</title>
<link rel="stylesheet"href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet"href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-
awesome.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<style>
.wrapper{
width: 600px;
margin: 0 auto;}
table tr td:last-child{
width: 120px;}
</style>
<script>
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</head>
<body>
<div class="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="mt-5 mb-3 clearfix">
<h2 class="pull-left">Employees Details</h2>
<a href="create.php"class="btnbtn-success pull-right"><iclass="fa fa-plus"></i> Add New Employee</a>
</div>
<?php
// Include config file
require_once"config.php";
echo"<tr>";
echo"<th>#</th>";
echo"<th>Name</th>";
echo"<th>Address</th>";
echo"<th>Salary</th>";
echo"<th>Action</th>";
echo"</tr>";
echo"</thead>";
echo"<tbody>";
while($row=mysqli_fetch_array($result)){
echo"<tr>";
echo"<td>".$row['id']."</td>";
echo"<td>".$row['name']."</td>";
echo"<td>".$row['address']."</td>";
echo"<td>".$row['salary']."</td>";
echo"<td>";
echo'<a href="read.php?id='.$row['id'].'" class="mr-3" title="View Record" data-toggle="tooltip"><span
class="fa fa-eye"></span></a>';
echo'<a href="update.php?id='.$row['id'].'" class="mr-3" title="Update Record" data-
toggle="tooltip"><span class="fa fa-pencil"></span></a>';
echo'<a href="delete.php?id='.$row['id'].'" title="Delete Record" data-toggle="tooltip"><span class="fa fa-
trash"></span></a>';
echo"</td>";
echo"</tr>";
}
echo"</tbody>";
echo"</table>";
// Free result set
mysqli_free_result($result);
}else{
echo'<div class="alert alert-danger"><em>No records were found.</em></div>';
}
}else{
echo"Oops! Something went wrong. Please try again later.";
}
// Close connection
mysqli_close($link);
?>
</div>
</div>
</div>
</div>
</body>
</html>
Once employees table is populated with some records the landing page i.e. the CRUD data grid may look
something like the picture shown below:
Conclusion:
ASSIGNMENT NO: 8
Title of Assignment:Buildadynamic webapplication usingStrut and performfollowing validations.
Problem Statement:
Designaloginpagewithentriesforname,mobilenumberemailidandloginbutton.Usestrutsand
performfollowing validations
a. Validationforcorrectnames
b. Validationfor mobilenumbers
c. Validationfor emailid
d. Validationif no enteredany value
e. Re-displayforwronglyentered valueswithmessage
f. Congratulationsand welcomepage uponsuccessful entries
Objectives:
Theory:
Apache Struts 2 is an open-source web application framework for developing Java EE web applications.
It uses and extends the Java Servlet API to encourage developers to adopt a model–view–controller
architecture. In this article, we will see how we can create a login page with validations using Struts 2.
We will use struts UI tags to create a login page.
Before creating your Struts2 project it is important to make sure that you have the Apache Tomcat server
installed and configured with the IDE of your choice like Eclipse. Now, if the above conditions are
fulfilled then follow all the steps given below. We are going to use Eclipse IDE so that all the required
components will be created under a Dynamic Web Project. Let us now start with creating Dynamic Web
Project.
Creating Dynamic Web Project
First, you simply need to start your Eclipse IDE and create a new Dynamic Web Project project. To do
this go to File > New > Dynamic Web Project and enter the project name as per your wish. I have
named it “struts_validation”
Select all the default options on the next screens and don’t forget to check the Generate web.xml
deployment descriptor option
Now copy all the files from the struts-2.2.3\lib folder to your project’s WEB-INF\lib folder. You can do
this by simply dragging and dropping all the files into the WEB-INF\lib folder. Your project structure
should now look like this
project structure
web.xml File:
Create a web.xml file under the webapp/WEB-INF folder and copy the following code in web.xml.
XML
<?xmlversion="1.0"encoding="UTF-8"?>
<web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
id="WebApp_ID"version="4.0">
<display-name>struts_validation</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
index.jsp File:
We need a JSP file to display the final result, this page will be called by the Struts 2 framework where a
predefined action will be called and this mapping is defined in the struts.xml file. So we will now create
an index.jsp under the webapp folder in your eclipse project. To create a JSP file, right-click on
the webapp folder in the project explorer and select New >JSP File.
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<title>Login</title>
<s:head/>
</head>
<bodybgColor="lightGreen">
<s:formaction="Login">
<s:textfieldname="userName"label="User Name"placeholder="Default 'Sanjyot'"/>
<s:passwordname="password"label="Password"/>
<s:textfieldname="phoneNumber"label="Phone Number"placeholder="10 digit phone number"/>
<s:textfieldname="email"label="Email"type="email"/>
<s:submitvalue="Login"/>
</s:form>
</body>
</html>
The <%@tagliburi=”/struts-tags” prefix=”s” %> is a directive that tells the Servlet Container that this
page will be using the Struts2 tags and these tags will be preceded by s. The s:form tag contains all the
form elements. When the user clicks on the Login button, the request is forwarded to the Login action
class.
welcome.jsp File:
Create welcome.jsp under the webapp folder and copy the following code into welcome.jsp
HTML
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<title>Login Successful</title>
</head>
<body>
<h3> Congratulations! You have logged in successfully.</h3>
<h4> Welcome <s:propertyvalue="userName"/>!!! </h4>
</body>
packagecom.SanjyotPanure.struts2;
importcom.opensymphony.xwork2.ActionSupport;
publicclassLogin extendsActionSupport {
privateString userName;
privateString password;
privateString phoneNumber;
privateString email;
publicvoidvalidate() {
if(getUserName().length() == 0) {
addFieldError("userName", "UserName is required");
}
elseif(!getUserName().equals("Sanjyot"))
{
addFieldError("userName", "Invalid User");
}
if(getPassword().length() == 0)
{
struts.xml File:
We need a mapping between URL to action mapping. The struts.xml maps the Login class, and the
welcome.jsp together. The mapping tells the Struts 2 framework which class will respond to the user’s
action (the URL), which method of that class will be executed, and what view to render based on the
String result that method returns. So we will now create a struts.xml file under the webapp/WEB-
INF folder. Copy the following code into struts.xml:
XML
<?xmlversion="1.0"encoding="UTF-8"?>
Here our “default” package extends the “struts-default” package. By extending the “struts-default”
package the action will by default inherit the set of interceptors defined in the default stack. The “struts-
default” package is defined in the struts-default.xml file.
If you’re running your project for the first time you’ll get a prompt as follows:
run on server
Output
Now expand localhost and select your tomcat server. After this click on the next and finish. You will see
a web page opened on your Eclipse IDE like this:
output screen
All the input fields are required. If you try to submit without entering details you will get a screen as
follows:
The Phone Number should be 10 digits. If you enter an incorrect phone number, you’ll get the following
screen:
The default User Name is “Sanjyot” and password you can enter anything. After you enter the correct
User Name you’ll get the following screen:
welcome screen
Conclusion:
ASSIGNMENT NO: 9
Title of Assignment:Design an application for registration using Angular JS.
e.g., Design registration (first name, last name, username, password) and login page using
Angular JS.
Objectives:
Theory:
The metadata for a service class provides the information Angular needs to make it available to
components through dependency injection (DI)
An application's components typically define many views, arranged hierarchically. Angular provides
the Router service to help you define navigation paths among views. The router provides sophisticated in-
browser navigational capabilities.
Model View Controller or MVC as it is popularly called, is a software design pattern for developing web
applications. A Model View Controller pattern is made up of the following three parts −
Model − It is the lowest level of the pattern responsible for maintaining data.
View − It is responsible for displaying all or a portion of the data to the user.
Controller − It is a software Code that controls the interactions between the Model and View.
MVC is popular because it isolates the application logic from the user interface layer and supports
separation of concerns. The controller receives all requests for the application and then works with the
model to prepare any data needed by the view. The view then uses the data prepared by the controller to
generate a final presentable response. The MVC abstraction can be graphically represented as follows.
The Model
The model is responsible for managing application data. It responds to the request from view and to the
instructions from controller to update itself.
The View
A presentation of data in a particular format, triggered by the controller's decision to present the data. They
are script-based template systems such as JSP, ASP, PHP and very easy to integrate with AJAX technology.
The Controller
The controller responds to user input and performs interactions on the data model objects. The controller
receives input, validates it, and then performs business operations that modify the state of the data model.
AngularJS is a MVC based framework. In the coming chapters, we will see how AngularJS uses MVC
methodology.
Steps:
You can also follow the steps given in the following Video:
https://drive.google.com/file/d/1E8RVocFtKXUOOPrXZ4S6ajZoNzdlL00R/view?usp=sharing
Sample Output:
Conclusion:
ASSIGNMENT NO: 10
Title of Assignment:BuildDesign and implement a business interface with necessary business logic for
any web application using Enterprise Java Beans (EJB).
Problem Statement: Design and implement a business interface with necessary business logic for any
web application
using EJB.
e.g., Design and implement the web application logic for deposit and withdraw amount
Transactions using EJB.
Theory:
Enterprise JavaBeans (EJB) is a specification for developing large-scale, distributed business applications
on the Java platform. The EJB architecture consists of three main components: enterprise beans (EJBs), the
EJB container, and the Java application server. EJBs run inside an EJB container, and the EJB container
runs inside a Java application server.
Enterprise Java Beans (EJB) is one of the several Java APIs for standard manufacture of enterprise
software. EJB is a server-side software element that summarizes business logic of an application.
Enterprise Java Beans web repository yields a runtime domain for web related software elements including
computer reliability, Java Servlet Lifecycle (JSL) management, transaction procedure and other web
services. The EJB enumeration is a subset of the Java EE enumeration.
The EJB enumeration aims to provide a standard way to implement the server-side business software
typically found in enterprise applications. Such machine code addresses the same types of problems, and
solutions to these problems are often repeatedly re-implemented by programmers. Enterprise Java Beans is
assumed to manage such common concerns as endurance, transactional probity and security in a standard
way that leaves programmers free to focus on the particular parts of the enterprise software at hand.
To run EJB application we need an application server (EJB Container) such as Jboss, Glassfish, Weblogic,
Websphere etc. It performs:
1. Life cycle management
2. Security
3. Transaction management
4. Object pooling
Architecture
The EJB architecture has two main layers, i.e., Application Server and EJB Container, based on which the
EJB architecture exist. The graphical representation of the EJB architecture is given below.
In the above diagram, the logical representation of how EJBs are invoked and deployed by using
RMI(Remote Method Invocation) is defined. The containers of the EJB cannot be self-deployed. In order
to deploy the containers, it requires the Application server.
Application Server
In the EJB architecture, the Application server is the outermost layer that holds or contains the Container to
be deployed. The application layer plays an important role in executing the application developed using the
beans. It provides the necessary environment to execute those applications. Some most popular application
servers are Web-logic, Tomcat, JBoss, Web-sphere, Wildfly, and Glass-finish. The main tasks of the
application server are:
1. Manage Interfaces
2. Execution of the processes
3. Connecting to the database
4. Manage other resources.
Container
In EJB architecture, the Container is the second outermost layer. It is a very important layer for enterprise
beans that are contained in it. For the enterprise bean, the Container provides various supporting services,
which are as follows:
o It provides support for transactional services such as registering the objects, assign remote
interfaces, purge the instances.
o It provides support for monitoring the object's activities and coordinating distributed components.
o It provides support for security services.
o It provides support for the pooling of resources.
o It provides support for managing the Life-cycle of beans and their concurrency.
o It provides support to concentrate on business logic.
Beans
Java beans of the enterprise are installed in the Container in the same way as a Plain old java object (POJO)
is installed and registered to the Container. For developing secured, large scale and robust business
applications, beans provide business logic.
2. Message Driven Bean: Like Session Bean, it contains the business logic but it is invoked by passing
message.
3. Entity Bean: It summarizes the state that can be remained in the database. It is deprecated. Now, it is
replaced with JPA (Java Persistent API). There are two types of entity bean:
1. EJB repository yields system-level services to enterprise beans, the bean developer can focus on solving
business problems. Rather than the bean developer, the EJB repository is responsible for system-level
services such as transaction management and security authorization.
2. The beans rather than the clients contain the application’s business logic, the client developer can focus
on the presentation of the client. The client developer does not have to code the pattern that execute
business rules or access databases. Due to this the clients are thinner which is a benefit that is particularly
important for clients that run on small devices.
3. Enterprise Java Beans are portable elements, the application assembler can build new applications from
the beans that already exists.
index.html:
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Implement Bank Application using EJB </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form method ="post" action="transact">
<h1> Bank Application using EJB </h1>
Enter Amount:<input type ="text" name="t1" /><br/><br/>
To create transact.java -- right click on -war file - select new servlet-- name: transact.java - Add
transact.java:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
import bankexamp.BankTransactLocal;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Rucha Pathari
*/
public class transact extends HttpServlet {
BankTransactLocalbankTransact = lookupBankTransactLocal();
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
if(selectedType.equals("deposit")){
bankTransact.deposit(amount);
}
if(selectedType.equals("withdraw")){
int amt=bankTransact.withdraw(amount);
out.println(amount+"successfully withdrawn. your balance is:"+amt);
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the
code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
private BankTransactLocallookupBankTransactLocal() {
try {
Context c = new InitialContext();
return (BankTransactLocal) c.lookup("java:global/Bank/Bank-
ejb/BankTransact!bankexamp.BankTransactLocal");
} catch (NamingException ne) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
}
}
To create BankTransact.java ---Right click on .ejb file select new session Bean -EJBname: BankTransact
package: bankexamp stateful—select local - finish
BankTransact.java:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bankexamp;
import javax.ejb.Stateful;
/**
*
* @author Rucha Pathari
*/
@Stateful
public class BankTransact implements BankTransactLocal {
int balance=10000;
@Override
public void deposit(int amount) {
balance=balance+amount;
}
@Override
public int withdraw(int amount) {
balance=balance-amount;
return balance;
}
Run:
SAMPLE OUTPUT:
Conclusion: