AssignmentNo.1to 11
AssignmentNo.1to 11
Assignment No: 1
Problem Statement: Case study: Before coding of the website, planning is important,
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 in following format:
Sr.No Website Purpose of Liked Disliked Evaluation
URL Website
From the evaluation, students should learn and conclude different website design
issues, which should be considered while developing a website.
Objectives: To learn the web based development environment.
Outcome: Students will be able to understand the importance of website planning and
website design issues .
Software & Hardware Requirments:
Operating System: Ubuntu
Hardware: i3 Processor, 4GB RAM, 500GB HDD
Theory:
1. Introduction
1.1 Internet and WWW
The Internet is the global system of interconnected computer networks that use the
Internet protocol suite (TCP/IP) to link devices worldwide.
It is a network of networks that consists of private, public, academic, business, and
government networks of local to global scope, linked by a broad array of electronic,
wireless, and optical networking technologies.
The Internet carries a vast range of information resources and services, such as the
inter-linked hypertext documents and applications of the World Wide Web (WWW),
electronic mail, telephony, and file sharing.
The World Wide Web (abbreviated WWW or the Web) is an information space
where documents and other web resources are identified by Uniform Resource
Locators (URLs), interlinked by hypertext links, and can be accessed via the Internet.
Web pages are primarily text documents formatted and annotated with Hypertext
Markup Language.
Department of Computer Engineering
PCET’s PCCOER, Pune-412101 Page1
Subject Name- WT Lab Class/Branch: TE Computer Engineering
2.6 Budgeting
The budget has to cover (at the very least):
• Planning - setting out requirements and perhaps a specification
• Design
• Implementation - including databases, associated support software,
integration with existing systems
• Testing - both functional and cross-platform compatibility
• Launch - deployment of component parts, website configuration
• Operational costs - hosting, marketing, CRM, secure certificate
• Website content management - in-house, out-of-house.
Frequently thought is only given to the design element, but some websites may
require web forms, databases, and perhaps integration with an existing sales order
processing system. Some calculation has to be done on the likely returns on
investment for a commercial website to keep the expenditure appropriate.
2.7 Commerce
There are specific issues with commerce that can cause problems. Apart from selling
something downloadable like software or reports (which are infinitely available) any
other system has to take account of stock either in-house or from a wholesaler. Even
selling software presents its own issues because a number of people making a
simultaneous download of a 25Mb app may have a serious impact on the
performance of the server, not just for the visitors doing the downloads, but also for
any others visiting the website.
Some of the issues are:
Conclusion:
Hence, we have successfully visited different website and identified different issues
in that website.
Assignment No: 2
Problem Statement: Implement a web page index.htm for any client website (e.g., a
restaurant website project) using following:
a. HTML syntax: heading tags, basic tags and attributes, frames, tables, images, lists,
links for text and images, forms etc.
b. Use of Internal CSS, Inline CSS, External CSS
Objectives: To use client side and server side web technologies.
Outcome: Apply the client side and server side technologies for web application
development
Software & Hardware Requirments:
Operating System: Ubuntu
Software: Gedit
Browser: Mozilla/Google Chrome
Hardware: i3 Processor, 4GB RAM, 500GB HDD
Theory:
1. HTML:
HTML stands for Hyper Text Markup Language, which is the most widely used language
on Web to develop web pages. HTML was created by Berners-Lee in late 1991 but "HTML
2.0" was the first standard HTML specification which was published in 1995. HTML 4.01
was a major version of HTML and it was published in late 1999. Though HTML 4.01 version
is widely used but currently we are having HTML-5 version which is an extension to HTML
4.01, and this version was published in 2012.
● Hypertext refers to the way in which Web pages (HTML documents) are linked
together. Thus, the link available on a webpage is called Hypertext.
● As its name suggests, HTML is a Markup Language which means you use HTML to
simply "mark-up" a text document with tags that tell a Web browser how to structure
it to display.
1.1 Basic HTML Document
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>This is a heading</h1>
</body>
</html>
<!DOCTYPE...> This tag defines the document type and HTML version.
<html> This tag encloses the complete HTML document and mainly comprises of
document header which is represented by <head>...</head> and document body which is
represented by <body>...</body> tags.
<head> This tag represents the document's header which can keep other HTML tags like
<title>, <link> etc.
<title> The <title> tag is used inside the <head> tag to mention the document title.
<body> This tag represents the document's body which keeps other HTML tags like <h1>,
<div>, <p> etc.
</body>
</body>
The <body> tag has following attributes which can be used to set different
colors −
● bgcolor − sets a color for the background of the page.
● text − sets a color for the body text.
● alink − sets a color for active links or selected links.
● link − sets a color for linked text.
● vlink − sets a color for visited links − that is, for linked text that you have
already clicked on.
1.4 Fonts
The font tag is having three attributes called size, color, and face to customize your fonts. To
change any of the font attributes at any time within your webpage, simply use the <font> tag.
The text that follows will remain changed until you close with the </font> tag. You can
change one or all of the font attributes within one <font> tag.
2. CSS
2.1 What is CSS?
● CSS stands for Cascading Style Sheets
● CSS describes how HTML elements are to be displayed on screen, paper, or in
other media
● CSS saves a lot of work. It can control the layout of multiple web pages all at once
● External stylesheets are stored in CSS files
● CSS is used to define styles for your web pages, including the design, layout and
variations in display for different devices and screen sizes.
<html><head>
<style>
p{
color: red;
text-align: center;
</style>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
#para1 {
text-align: center;
color: red;
</style>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html><head>
<style>
.center {
text-align: center;
color: red;
</style>
</head>
<body>
</body></html>
2.4 Types:
2.4.1 External Style Sheet:
With an external style sheet, you can change the look of an entire website by changing just
one file. An external style sheet can be written in any text editor. The file should not contain
any html tags. The style sheet file must be saved with a .css extension. Each page must
include a reference to the external style sheet file inside the <link> element. The <link>
element goes inside the <head> section:
mystyle.css
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
<html>
<head>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
<html>
<head>
<style>
body {
background-color: linen;
h1 {
color: maroon;
margin-left: 40px;
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body></html>
<html>
<body>
</h1>
<p>This is a paragraph.</p>
</body>
</html>
Conclusion:
Hence, we have successfully designed web page index.htm using HTML and CSS.
1. style.css
body
background-image: url("img.jpeg");
background-repeat: no-repeat;
background-size: cover;
input[type="password"], input[type="text"]
border:1px solid;
background-color:rgba(0,0,0,0.0);
height: 33px;
width:240px;
padding-left: 10px;
input[type="submit"]
background-color: #4CAF50;
color: white;
height: 42px;
width: 250px;
padding-left: 10px;
input[type="submit"]:hover
background-image: linear-gradient(#4ec7c0,#31aba3)
input[type="submit"]:active
padding: 0;
2. login.html
<!DOCTYPE html>
<html>
<head>
<style>
.login
border-radius: 5px;
height: 200px;
width: 310px;
border-color:#3498DB;
padding-top: 20px;
.register
border-radius: 5px;
height: 350px;
width: 310px;
border-color:#3498DB;
padding-top: 20px;
</style>
</head>
<body>
<div class="login">
<label><b>Username</b></label>
<label><b>Password</b></label>
</form>
</div>
</body>
</html>
OutPut:
1. login
FAQs:
1. What is the difference between HTML and HTML5?
2. What is the difference between html elements and tags?
3. What is marquee?
4. What is the use of span tag? Give an example?
5. What is the use of ‘required ’attribute in HTML5?
6. What is External stylesheet? What are the advantages and disadvantages?
7. What is CSS selector?
8. What are the components of CSS style?
9. What is browser safe color?
10. Explain difference between HTML and XML?
Assignment No: 3
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
Objectives: To use client side and server side web technologies.
Outcome: Apply the client side and server side technologies for web application
development
Software & Hardware Requirments:
Operating System: Ubuntu
Software: Gedit
Browser: Mozilla/Google Chrome
Hardware: i3 Processor, 4GB RAM, 500GB HDD
Theory:
1. CSS
1.1 What is CSS?
● CSS stands for Cascading Style Sheets
● CSS describes how HTML elements are to be displayed on screen, paper, or in
other media
● CSS saves a lot of work. It can control the layout of multiple web pages all at once
● External stylesheets are stored in CSS files
● CSS is used to define styles for your web pages, including the design, layout and
variations in display for different devices and screen sizes.
<html><head>
<style>
p {
color: red;
text-align: center;
</style>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
#para1 {
text-align: center;
color: red;
</style>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html><head>
<style>
.center {
text-align: center;
color: red;
</style>
</head>
<body>
</body></html>
1.4 Types:
1.4.1 External Style Sheet:
With an external style sheet, you can change the look of an entire website by changing just
one file. An external style sheet can be written in any text editor. The file should not contain
any html tags. The style sheet file must be saved with a .css extension. Each page must
include a reference to the external style sheet file inside the <link> element. The <link>
element goes inside the <head> section:
mystyle.css
body {
background-color:
lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
<html>
<head>
<link rel="stylesheet"
type="text/css" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: linen;
h1 {
color: maroon;
margin-left: 40px;
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body></html>
<html>
<body>
</h1>
<p>This is a paragraph.</p>
</body>
</html>
2. XML
XML stands for Extensible Markup Language and is a text-based markup language
derived from Standard Generalized Markup Language (SGML).
● XML is extensible − XML allows you to create your own self-descriptive tags, or
language, that suits your application.
● XML carries the data, does not present it − XML allows you to store the data
irrespective of how it will be presented.
● 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.
3. All XML Elements Must Have a Closing Tag :In HTML, some elements might
work well, even with a missing closing tag, In XML, it is illegal to omit the closing
tag. All elements must have a closing tag.
4. XML Tags are Case Sensitive : XML tags are case sensitive. The tag <Letter> is
different from the tag <letter>. Opening and closing tags must be written with
the same case
5. XML Elements Must be Properly Nested: In HTML, you might see improperly
nested elements:
<b><i>This text is bold and
italic</b></i>
6. XML Attribute Values Must be Quoted :XML elements can have attributes in
name/value pairs just like in HTML. In XML, the attribute values must always be
quoted.
<note date="12/11/2007">
<to>Tove</to>
<from>Jani</from>
</note>
7. Entity References : Some characters have a special meaning in XML. If you place a
character like "<" inside an XML element, it will generate an error because the parser
interprets it as the start of a new element.
<message>salary < 1000</message>
Conclusion:
Hence, we have successfully designed the XML document to store the information of
the employees and display the content in tabular format by using CSS.
Program:
Home.html
<html>
<head>
<style>
table, th, td
border-collapse:collapse;
th, td
padding: 5px;
</style>
</head>
<body>
<br><br>
<table id="demo">
</table>
<script>
function loadXMLDoc()
xmlhttp.onreadystatechange = function() {
myFunction(this);
};
xmlhttp.send();
function myFunction(xml)
var i;
var table="<tr><th>EmpName</th><th>Address</th><th>organization</th></tr>";
var x = xmlDoc.getElementsByTagName("employee");
table += "<tr><td>" +
x[i].getElementsByTagName("empname")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("address")[0].childNodes[0].nodeValue +
"</td><td>"+x[i].getElementsByTagName("organization")[0].childNodes[0].nodeVal
ue +
"</td></tr>";
document.getElementById("demo").innerHTML = table;
</script>
</body>
</html>
emp.xml
<information>
<employee>
<empname>NileshKorade</empname>
<address>Pune</address>
<organization>PCCOER</organization>
</employee>
<employee>
<empname>AmolDumbare</empname>
<address>Nigdi</address>
<organization>HCL Technology</organization>
</employee>
<employee>
<empname>GaneshAdmane</empname>
<address>Solapur</address>
<organization>TCS</organization>
</employee>
</information>
Output:
FAQs:
1. Explain difference between HTML and XML?
2. What is XML DOM?
3. Explain difference between CDATA and PCDATA?
4. What is mean by simple element and complex element?
5. What is XPATH?
6. Explain XSL and XSLT?
Assignment No: 4
Problem Statement: Implement an application in Java Script using following:
a) Design UI of application using HTML, CSS etc.
b) Include Java script validation
c) Use of prompt and alert window using Java Script
Objectives: To use client side and server side web technologies.
Outcome: Apply the client side and server side technologies for web application
development
Software & Hardware Requirments:
Operating System: Ubuntu
Software: Gedit
Browser: Mozilla/Google Chrome
Hardware: i3 Processor, 4GB RAM, 500GB HDD
Theory:
1. JavaScript
1. 1. History
JavaScript is a lightweight, interpreted programming language. It is designed for
creating network-centric applications. It is complimentary to and integrated with Java.
JavaScript is very easy to implement because it is integrated with HTML. It is open and
cross-platform.
JavaScript is a dynamic computer programming language. It is lightweight and most
commonly used as a part of web pages, whose implementations allow client-side script to
interact with the user and make dynamic pages. It is an interpreted programming language
with object-oriented capabilities.
JavaScript was first known as LiveScript, but Netscape changed its name to
JavaScript, possibly because of the excitement being generated by Java. JavaScript made its
first appearance in Netscape 2.0 in 1995 with the name LiveScript.
The general-purpose core of the language has been embedded in Netscape, Internet
Explorer, and other web browsers.
JavaScript is a lightweight, interpreted programming language.
Designed for creating network-centric applications.
Complementary to and integrated with Java.
Complementary to and integrated with HTML.
Open and cross-platform
1. 2. Limitations
Client-side JavaScript does not allow the reading or writing of files. This has been
kept for security reason.
JavaScript cannot be used for networking applications because there is no such
support available.
JavaScript doesn't have any multithreading or multiprocessor capabilities.
1.3. </script>
JavaScript can be implemented using JavaScript statements that are placed within the
<script>... </script> HTML tags in a web page.
You can place the <script> tags, containing your JavaScript, anywhere within
you web page, but it is normally recommended that you should keep it within the
<head> tags.
JavaScript code
</script>
1.4. Example
<html>
<body>
<!--
document.write("Hello World!")
//-->
</script>
</body>
</html>
The comment ends with a "//-->". Here "//" signifies a comment in JavaScript, so we
add that to prevent a browser from reading the end of the HTML comment as a piece of
JavaScript code. Next, we call a function document.write which writes a string into our
HTML document.
This function can be used to write text, HTML, or both.
1. 8. Comments in JavaScript
JavaScript supports both C-style and C++-style comments, Thus −
Any text between a // and the end of a line is treated as a comment and is ignored by
JavaScript.
Any text between the characters /* and */ is treated as a comment. This may span
multiple lines.
JavaScript also recognizes the HTML comment opening sequence <!--. JavaScript
treats this as a single-line comment, just as it does the // comment.
The HTML comment closing sequence --> is not recognized by JavaScript so it
should be written as //-->.
<!--
/*
*/
//-->
</script>
<head>
<script type="text/javascript">
<!--
function sayHello()
alert("Hello World")
//-->
</script>
</head>
<body>
</body>
</html>
<head> </head>
<body>
<script type="text/javascript">
<!--
document.write("Hello World")
//-->
</script>
</body>
</html>
<head>
<script type="text/javascript">
<!--
function sayHello()
alert("Hello World")
//-->
</script>
</head>
<body>
<script type="text/javascript">
<!--
document.write("Hello World")
//-->
</script>
</body>
</html>
function sayHello()
<html>
<head>
</head>
<body>
</html>
1.10 Variables
One of the most fundamental characteristics of a programming language is the set of
data types it supports. These are the type of values that can be represented and manipulated in
a programming language.
JavaScript allows you to work with three primitive data types −
Numbers, eg. 123, 120.50 etc.
Strings of text e.g. "This text string" etc.
Boolean e.g. true or false.
Note − Java does not make a distinction between integer values and floating-
point values. All numbers in JavaScript are represented as floating-point values.
<!--
var money;
var name;
//-->
</script>
You can also declare multiple variables with the same var keyword as follows −
<script type="text/javascript">
<!--
//-->
</script>
<script type="text/javascript">
<!--
var money;
money = 2000.50;
//-->
</script>
Note − Use the var keyword only for declaration or initialization, once for the life of any
variable name in a document. You should not re-declare same variable twice.
JavaScript is untyped language. This means that a JavaScript variable can hold a
value of any data type. Unlike many other languages, you don't have to tell JavaScript during
variable declaration what type of value the variable will hold. The value type of a variable
can change during the execution of a program and JavaScript takes care of it automatically.
<!--
function checkscope( )
document.write(myVar);
//-->
</script>
</body>
</html>
● JavaScript variable names should not start with a numeral (0-9). They must
begin with a letter or an underscore character. For example, 123test is an
invalid variable name but _123test is a valid one.
● JavaScript variable names are case-sensitive. For example, Name and name
are two different variables.
1.11 Functions
Before we use a function, we need to define it. The most common way to define a function in
JavaScript is by using the function keyword, followed by a unique function name, a list of
parameters (that might be empty), and a statement block surrounded by curly braces.
<html>
<head>
<script type="text/javascript">
function sayHello()
</script>
</head>
<body>
<form>
</form>
</body>
</html>
<html>
<head>
<script type="text/javascript">
var full;
return full;
function secondFunction()
var result;
document.write (result );
</script>
</head>
<body>
<form>
</form>
</body>
</html>
1.12 Events
JavaScript's interaction with HTML is handled through events that occur when the user or the
browser manipulates a page.
When the page loads, it is called an event. When the user clicks a button, that click too is an
event. Other examples include events like pressing any key, closing a window, resizing a
window, etc.
<html>
<head>
<script type="text/javascript">
function sayHello()
alert("Hello World")
</script>
</head>
<body>
<form>
</form>
</body>
</html>
Conclusion:
Hence, we have successfully designed UI of application using HTML, CSS and
performed validation using Java script.
Program
1. style.css
body
background-image: url("img.jpeg");
background-repeat: no-repeat;
background-size: cover;
.login
border-radius: 5px;
height: 200px;
width: 310px;
border-color:#3498DB;
padding-top: 20px;
.register
border-radius: 5px;
height: 350px;
width: 310px;
border-color:#3498DB;
padding-top: 20px;
input[type="password"], input[type="text"]
border:1px solid;
background-color:rgba(0,0,0,0.0);
height: 33px;
width:240px;
padding-left: 10px;
input[type="submit"]
background-color: #4CAF50;
color: white;
height: 42px;
width: 250px;
padding-left: 10px;
input[type="submit"]:hover
background-image: linear-gradient(#4ec7c0,#31aba3)
input[type="submit"]:active
padding: 0;
2. login.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="login">
<label><b>Username</b></label>
<label><b>Password</b></label>
</form>
</div>
</body>
</html>
3. welcome.html
<!DOCTYPE html>
<html>
<body>
</center>
</body>
</html>
4. register.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function validateform()
var pass=document.myform.password.value;
if(pass.length<4)
return false;
var mobile=document.myform.mobile.value;
if(isNaN(mobile))
return false;
else if (mobile.length<10||mobile.length>10)
return false;
return false;
var age=document.myform.age.value;
if(isNaN(age))
return false;
return true;
</script>
</head>
<body>
<div class="register">
<label><b>Username</b></label>
<label><b>Password</b></label>
<label><b>Mobile Number</b></label>
<label><b>E-Mail Address</b></label>
<label><b>Age</b></label>
</form>
</body>
</html>
OutPut:
1. login
2. Registration
FAQs:
Assignment No: 5
Problem Statement: Implement the sample program demonstrating the use of
Servlet.
Objectives: To use client side and server side web technologies.
Outcome: Apply the client side and server side technologies for web application
development
Software & Hardware Requirments:
Operating System: Ubuntu
Software: Eclipse
Programming Language: Java(Servlet/JSP)
Server: Tomcat
Browser: Mozilla/Google Chrome
Hardware: i3 Processor, 4GB RAM, 500GB HDD
Theory:
1. Servlet
Java Servlets are programs that run on a Web or Application server and act as a
middle layer between a request coming from a Web browser or other HTTP client and
databases or applications on the HTTP server. Using Servlets, you can collect input from
users through web page forms, present records from a database or another source, and create
web pages dynamically. Java Servlets often serve the same purpose as programs implemented
using the Common Gateway Interface (CGI).
The init method is designed to be called only once. It is called when the servlet is first
created, and not called again for each user request. So, it is used for one-time initializations,
just as with the init method of applets.
When a user invokes a servlet, a single instance of each servlet gets created, with each
user request resulting in a new thread that is handed off to doGet or doPost as appropriate.
The init() method simply creates or loads some data that will be used throughout the life of
the servlet.
The init method definition looks like this:
public void init() throws ServletException
// Initialization code...
// Finalization code...
1.3 Examples
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Do required initialization
response.setContentType("text/html");
// do nothing.
Conclusion:
Hence, we have successfully designed web page to demonstrate the use of Servlet.
.
Program
ShowBookInfo.java
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/ShowBookInfo")
public class ShowBookInfo extends HttpServlet {
out.print("<tr><th>BookId</th><th>BookName</th><th>Author</th><th>Prize</th><th
>Quantity</th></tr>");
while(rs.next())
{
out.print("<tr>");
out.print("<td>"+rs.getString(1)+"</td>");
out.print("<td>"+rs.getString(2)+"</td>");
out.print("<td>"+rs.getString(3)+"</td>");
out.print("<td>"+rs.getInt(4)+"</td>");
out.print("<td>"+rs.getInt(5)+"</td>");
out.print("</tr>");
}
out.print("</table></center>");
}
catch(Exception e)
{
}
Database
Output:
FAQs:
1. What is Servlet?
2. Explain life cycle of servlet?
3. What is session management?
4. Explain advantages of Servlet over CGI?
Assignment No: 6
Problem Statement: Implement the sample program demonstrating the use of JSP.
Objectives: To use client side and server side web technologies.
Outcome: Apply the client side and server side technologies for web application
development
Software & Hardware Requirments:
Operating System: Ubuntu
Software: Eclipse
Programming Language: Java(Servlet/JSP)
Server: Tomcat
Browser: Mozilla/Google Chrome
Hardware: i3 Processor, 4GB RAM, 500GB HDD
Theory:
1. JavaServer Pages.
JavaServer Pages (JSP) is a technology for developing web pages that support
dynamic content which helps developers insert java code in HTML pages by making use of
special JSP tags, most of which start with <% and end with %>.
A JavaServer Pages component is a type of Java servlet that is designed to fulfill 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 embedded JSP actions and
commands.
Using JSP, you can collect input from users through web page forms, present records
from a database or another source, and create web pages dynamically.
JSP tags can be used for a variety of 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.
● Finally, JSP is an integral part of Java EE, a complete platform for enterprise class
applications. This means that JSP can play a part in the simplest applications to the
most complex and demanding.
JSP Processing:
The following steps explain how the web server creates the web page using JSP:
● As with a normal page, your browser sends an HTTP request to the web server.
● The web server recognizes that the HTTP request is for a JSP page and forwards it to
a JSP engine. This is done by using the URL or JSP page which ends with .jsp instead
of .html.
● The JSP engine loads the JSP page from disk and converts it into a servlet content.
This conversion is very simple in which all template text is converted to println( )
statements and all JSP elements are converted to Java code that implements the
corresponding dynamic behavior of the page.
● The JSP engine compiles the servlet into an executable class and forwards the original
request to a servlet engine.
● A part of the web server called the servlet engine loads the Servlet class and executes
it. During execution, the servlet produces an output in HTML format, which the
servlet engine passes to the web server inside an HTTP response.
● The web server forwards the HTTP response to your browser in terms of static HTML
content.
● Finally web browser handles the dynamically generated HTML page inside the HTTP
response exactly as if it were a static page.
● All the above mentioned steps can be shown below in the following diagram:
// Initialization code...
Typically initialization is performed only once and as with the servlet init method,
you generally initialize database connections, open files, and create lookup tables in the
jspInit method.
HttpServletResponse response)
The _jspService() method of a JSP is invoked once per a request and is responsible
for generating the response for that request and this method is also responsible for generating
responses to all seven of the HTTP methods ie. GET, POST, DELETE etc.
Any text, HTML tags, or JSP elements you write must be outside the scriptlet.
Following is the simple and first example for JSP:
<html>
<head><title>Hello World</title></head>
<body>
Hello World!<br/>
<%
%>
</body>
</html>
</jsp:expression>
<body>
</body>
</html>
context.
config This is the ServletConfig object associated with the page.
This encapsulates use of server-specific features like higher
pageContext
performance JspWriters.
This is simply a synonym for this, and is used to call the
page
methods defined by the translated servlet class.
The Exception object allows the exception data to be accessed
Exception
by designated JSP.
Conclusion:
Hence, we have successfully designed web page to demonstrate the use of JSP.
.
Program
showinfo.jsp
<%@pageimport="java.sql.*"language="java"contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPEhtml>
<html>
<head>
<metacharset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
out.print("<h2>Student Information Table</h2>");
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from studentinfo");
out.print("<center><table border=\"1\">");
out.print("<tr><th>Id</th><th>Student
Name</th><th>Class</th><th>Division</th><th>City</th></tr>");
while(rs.next())
{
out.print("<tr>");
out.print("<td>"+rs.getString(1)+"</td>");
out.print("<td>"+rs.getString(2)+"</td>");
out.print("<td>"+rs.getString(3)+"</td>");
out.print("<td>"+rs.getString(3)+"</td>");
out.print("<td>"+rs.getString(5)+"</td>");
out.print("</tr>");
}
out.print("</table></center>");
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</body>
</html>
DataBase:
OutPut:
FAQs:
1. What is JSP?
2. What is the syntax of JSP?
3. How do we connect JSP file to database?
4. What is session management?
5. Explain advantages of JSP over Servlet?
6. Explain Scriptlet, Expression, Declaration tag in JSP?
7. List default object in JSP?
Assignment No: 7
Problem Statement: Build a dynamic web application using PHP and MySQL.
a. Create database tables in MySQL and create connection with PHP.
b. Create the add, update, delete and retrieve functions in the PHP web app
interacting with MySQL database
Objectives: To use client side and server side web technologies.
Outcome: Apply the client side and server side technologies for web application
development
Software & Hardware Requirments:
Operating System: Ubuntu
Software: Gedit
Programming Language: PhP
Server: Wamp
Browser: Mozilla/Google Chrome
Hardware: i3 Processor, 4GB RAM, 500GB HDD
Theory:
1. PHP
The PHP Hypertext Preprocessor (PHP) is a programming language that allows web
developers to create dynamic content that interacts with databases. PHP is basically used for
developing web based software applications.
1.1 Introduction
● PHP started out as a small open source project that evolved as more and more people
found out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way
back in 1994.
● PHP is a recursive acronym for "PHP: Hypertext Preprocessor".
● PHP is a server side scripting language that is embedded in HTML. It is used to
manage dynamic content, databases, session tracking, even build entire e-commerce
sites.
● It is integrated with a number of popular databases, including MySQL, PostgreSQL,
Oracle, Sybase, Informix, and Microsoft SQL Server.
● PHP supports a large number of major protocols such as POP3, IMAP, and LDAP.
PHP4 added support for Java and distributed object architectures (COM and
CORBA), making n-tier development a possibility for the first time.
1.2 Features
● PHP Syntax is C-Like.
● PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
● PHP is compatible with almost all servers used today (Apache, IIS, etc.)
● PHP supports a wide range of databases
● PHP is free. Download it from the official PHP resource: www.php.net
● PHP is easy to learn and runs efficiently on the server side
● PHP can generate dynamic page content
● PHP can create, open, read, write, delete, and close files on the server
● PHP can collect form data
● PHP can send and receive cookies
● PHP can add, delete, modify data in your database
● PHP can be used to control user-access
● PHP can encrypt data
<body>
</body>
</html>
?>
Multi-lines comments
/* This is a comment with multiline
Subject: PHP
*/
PHP has a total of eight data types which we use to construct our variables −
Integers − are whole numbers, without a decimal point, like 4195.
Doubles − are floating-point numbers, like 3.14159 or 49.1.
Booleans − have only two possible values either true or false.
NULL − is a special type that only has one value: NULL.
Strings − are sequences of characters, like 'PHP supports string
operations.'
Arrays − are named and indexed collections of other values.
Objects − are instances of programmer-defined classes, which can
package up both other kinds of values and functions that are specific to
the class.
Resources − are special variables that hold references to resources
external to PHP (such as database connections).
<?php
$many = 2.2888800;
$many_2 = 2.2111200;
?>
define("MINSIZE", 50);
echo MINSIZE;
?>
{
echo "Have a good morning!";
}
{
echo "Have a good day!";
}
else
{
echo "Have a good night!";
}
?>
{
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
?>
{
echo "The number is: $x <br>";
$x++;
}
?>
{
echo "The number is: $x <br>";
}
?>
{
echo "$value <br>";
}
?>
<head>
</head>
<body>
<?php
addFunction(10, 20);
?>
</body>
</html>
PHP Functions - Returning values :To let a function return a value, use the return
statement.
<?php
function sum($x, $y)
{
$z = $x + $y;
return $z;
}
<?php
$dbhost = 'localhost:3036';
$dbuser = 'guest';
$dbpass = 'guest123';
if(! $conn ) {
mysql_close($conn);
?>
Data can be entered into MySQL tables by executing SQL INSERT statement through PHP
function mysql_query.
<?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = 'rootpassword';
if(! $conn ) {
mysql_select_db('test_db');
if(! $retval ) {
mysql_close($conn);
?>
Conclusion:
Hence, we have successfully created database tables in MySQL and performed add,
update, delete and retrieve functions in the PHP
Program
Index.html
<html>
<head>
<link rel = "stylesheet" type = "text/css" href = "style.css"/>
</head>
<style>
input[type="submit"]
{
background-color: #4CAF50;
color: white;
height: 42px;
margin: 10px 0 0 36px;
width: 250px;
padding-left: 10px;
}
</style>
<body>
<form action="deletedata.php">
<input type="submit"value="Delete">
</form>
<form action="updatedata.php">
<input type="submit"value="Update">
</form>
<form action="showdata.php">
<input type="submit"value="Show">
</form>
<form action="insertdata.php">
<input type="submit"value="Insert">
</form>
</body>
</htm>
showdata.php
<?php
$db_name = 'student';
$db_user = 'root';
$db_pass = 'root';
$db_host = 'localhost';
$result = $conn->query($sql);
if ($result->num_rows >0)
{
echo'<table border="1">';
echo
"<tr><th>Name</th><th>Roll</th><th>Class</th><th>Address</th></tr>";
while($row = $result->fetch_assoc())
{
$name =$row['name'];
$roll=$row['roll'];
$class =$row['class'];
$address =$row['address'];
echo "<tr><td>".$name
."</td><td>".$roll."</td><td>".$class."</td><td>".$address."</td></tr>";
}
echo"</table>";
}
$conn->close();
}
?>
<html>
<head>
</head>
<body>
<h2><a href="index.html">Click Here !!! fro Home Page</a?</h2>
</body>
</html>
insertdata.php
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$name = $_POST['name'];
$roll = $_POST['roll'];
$class =$_POST['class'];
$address=$_POST['address'];
$db_name = 'student';
$db_user = 'root';
$db_pass = 'root';
$db_host = 'localhost';
else
{ echo "Error: ". $sql . "<br>". $conn->error;
echo"<center><font color=\"red\">Problem in Inserting
data</font></center>";
}
}
$conn->close();
}
?>
<html>
<head>
<style>
input[type="password"], input[type="text"]
{
border:1px solid;
background-color:rgba(0,0,0,0.0);
height: 33px;
width:240px;
margin: 2px 0 0 36px;
padding-left: 10px;
input[type="submit"]
{
background-color: #4CAF50;
color: white;
height: 42px;
margin: 10px 0 0 36px;
width: 250px;
padding-left: 10px;
}
</style>
</head>
<body>
<form action=""name="myform"method="post">
<label><b>StudentName:</b></label>
<br><input type="text"name="name"id="name"placeholder=
"Username"required="required"onfocus="this.value = '';">
<br><label><b>Roll No:</b></label>
<br><input type="text"name="roll"id="roll"placeholder= "Roll
No"required="required"onfocus="this.value = '';">
<br><label><b>Class:</b></label>
<br><input type="text"name="class"id="class"placeholder=
"Class"required="required"onfocus="this.value = '';">
<br><label><b>Address:</b></label>
<br><input type="text"name="address"id="address"placeholder=
"Address"required="required"onfocus="this.value = '';">
updatedata.php
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$name = $_POST['name'];
$roll = $_POST['roll'];
$class =$_POST['class'];
$address=$_POST['address'];
$db_name = 'student';
$db_user = 'root';
$db_pass = 'root';
$db_host = 'localhost';
Successfully</font></center>";
}
else
{ echo "Error: ". $sql . "<br>". $conn->error;
echo"<center><font color=\"red\">Problem in Updating
data</font></center>";
}
}
$conn->close();
}
?>
<html>
<head>
<style>
input[type="password"], input[type="text"]
{
border:1px solid;
background-color:rgba(0,0,0,0.0);
height: 33px;
width:240px;
margin: 2px 0 0 36px;
padding-left: 10px;
input[type="submit"]
{
background-color: #4CAF50;
color: white;
height: 42px;
margin: 10px 0 0 36px;
width: 250px;
padding-left: 10px;
}
</style>
</head>
<body>
<form action=""name="myform"method="post">
<label><b>StudentName:</b></label>
<br><input type="text"name="name"id="name"placeholder=
"Username"required="required"onfocus="this.value = '';">
<br><label><b>Roll No:</b></label>
<br><input type="text"name="roll"id="roll"placeholder= "Roll
No"required="required"onfocus="this.value = '';">
<br><label><b>Class:</b></label>
<br><input type="text"name="class"id="class"placeholder=
"Class"required="required"onfocus="this.value = '';">
<br><label><b>Address:</b></label>
<br><input type="text"name="address"id="address"placeholder=
"Address"required="required"onfocus="this.value = '';">
deletedata.php
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$roll = $_POST['roll'];
$db_name = 'student';
$db_user = 'root';
$db_pass = 'root';
$db_host = 'localhost';
else
{ echo "Error: ". $sql . "<br>". $conn->error;
echo"<center><font color=\"red\">Problem in Updating
data</font></center>";
}
$conn->close();
}
?>
<html>
<head>
<style>
input[type="password"], input[type="text"]
{
border:1px solid;
background-color:rgba(0,0,0,0.0);
height: 33px;
width:240px;
margin: 2px 0 0 36px;
padding-left: 10px;
input[type="submit"]
{
background-color: #4CAF50;
color: white;
height: 42px;
margin: 10px 0 0 36px;
width: 250px;
padding-left: 10px;
}
</style>
</head>
<body>
<br><label><b>Roll No:</b></label>
<br><input type="text"name="roll"id="roll"placeholder= "Roll
No"required="required"onfocus="this.value = '';">
OutPut:
Database
FAQs:
1. What is the use of "echo" in php?
2. How to include a file to a php page?
3. Differences between GET and POST methods ?
4. What is the use of 'print' in php?
5. What is the difference between Session and Cookie?
6. What are the different errors in PHP?
7. How to print current date and time?
8. What is the difference between sql and Mysql?
9. Why do we use GROUP BY and ORDER BY function in mysql?
10. What is JOIN in MySQL? What are the different types of join?
Assignment No: 8
Problem Statement: Design a login page with entries for name, mobile number
email id and login button. Use struts and perform following validations
a. Validation for correct names
b. Validation for mobile numbers
c. Validation for email id
d. Validation if no entered any value
e. Re-display for wrongly entered values with message
f. Congratulations and welcome page upon successful entries
Objectives: To use web technology languages, frameworks and services.
Outcome: Analyze the web technology languages, frameworks and services
Software & Hardware Requirments:
Operating System: Ubuntu
Software: Eclipse
Programming Language: Java
Server: Tomcar
Browser: Mozilla/Google Chrome
Hardware: i3 Processor, 4GB RAM, 500GB HDD
Theory:
1. Introduction
The struts 2 framework is used to develop MVC-based web application. The Struts 2
framework is used to develop MVC (Model View Controller) based web applications. Struts
2 is the combination of webwork framework of opensymphony and struts 1.
Struts 2 provides many features that were not in struts 1. The important features of struts 2
framework are as follows:
1. Configurable MVC components
2. POJO based actions
3. AJAX support
4. Integration support
5. Various Result Types
6. Various Tag support
7. Theme and Template support
View The view module is responsible to display data i.e. it represents the presentation.
Controller The controller module acts as an interface between view and model. It intercepts
all the requests i.e. receives input and commands to Model / View to change accordingly.
2. Components
2.1 web.xml
web.xml file Provide the entry of Controller. In struts
2, StrutsPrepareAndExecuteFilter class works as the controller. As we know well, struts 2
uses filter for the controller. It is implicitly provided by the struts framework.
1. <?xml version="1.0" encoding="UTF-8"?>
2. <web-app>
3. <filter>
4. <filter-name>struts2</filter-name>
5. <filter-class>
6. org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
7. </filter-class>
8. </filter>
9.
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
2.2 struts.xml
It is the important file from where struts framework gets information about the action and
decides which result to be invoked. Here, we have used many elements such as struts,
package, action and result.
struts element is the root elements of this file. It represents an application.
package element is the sub element of struts. It represents a module of the
application. It generally extends the struts-default package where many interceptors
and result types are defined.
action element is the sub element of package. It represents an action to be invoked for
the incoming request. It has name, class and method attributes. If you don't specify
name attribute by default execute() method will be invoked for the specified action
class.
result element is the sub element of action. It represents an view (result) that will be
invoked. Struts framework checks the string returned by the action class, if it returns
success, result page for the action is invoked whose name is success or has no name.
It has name and type attributes. Both are optional. If you don't specify the result
name, by default success is assumed as the result name. If you don't specify the type
attribute, by default dispatcher is considered as the default result type. We will learn
about result types later.
4. <struts>
7. <result name="success">welcome.jsp</result>
8. </action>
</package>
</struts>
This is simple bean class. In struts 2, action is POJO (Plain Old Java Object). It has one extra
method execute i.e. invoked by struts framework by default.
2.5 StrutsPrepareAndExecuteFilter
Handles both the preparation and execution phases of the Struts dispatching process. This
filter is better to use when you don't have another filter that needs access to action context
information, such as Sitemesh.
StrutsPrepareAndExecuteFilter belongs to org.apache.struts2.dispatcher.ng.filter
package. StrutsPrepareAndExecuteFilter can also be understood by its name.
StrutsPrepareAndExecuteFilter has the responsibility to prepare and execute all phases of
struts. The question is when we shouldz use StrutsPrepareAndExecuteFilter filter. Struts 2
apache documentation says that when there is no other filter being used that can access action
context information, better to use StrutsPrepareAndExecuteFilter filter.
3. {
5. {
6. return "success";
7. }
8. }
execute() - This method executed automatically when action is called. This is default
implemented method subclasses should implement this method by proving their business
logic.
validate() - This method is default implemented method subclasses should override this
method to provide validation.
clearErrors() - This method can be used when you want to continue execution, and want to
clear the state of the action.
Conclusion:
Hence, we have successfully designed a login page with entries for name, mobile number
email id and login button and used struts and perform validation.
Program
web.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/x
ml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-
app_3_1.xsd"id="WebApp_ID"version="3.1">
<display-name>AAStrutsApplication</display-name>
<welcome-file-list>
<welcome-file>Registration.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>Struts2</filter-name>
<filter-
class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
struts.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEstrutsPUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<includefile="struts-default.xml"></include>
<packagename="default"namespace="/"extends="struts-default">
<actionname="register"class="nilesh.korade.RegistrationAction">
<resultname="success">/Welcome.jsp</result>
<resultname="input">/Registration.jsp</result>
</action>
</package>
RegistrationAction.java
packagenilesh.korade;
importcom.opensymphony.xwork2.ActionSupport;
publicclassRegistrationActionextendsActionSupport{
String emailid;
String name;
longcontactno;
publicString execute() throwsException
{
returnSUCCESS;
}
publicString getEmailid() {
returnemailid;
}
publicvoidsetEmailid(String emailid) {
this.emailid= emailid;
}
publicString getName() {
returnname;
}
publicvoidsetName(String name) {
this.name= name;
}
publiclonggetContactno() {
returncontactno;
}
publicvoidsetContactno(longcontactno) {
this.contactno= contactno;
}
}
RegistrationAction-validation.xml
<!DOCTYPEvalidatorsPUBLIC"-//Apache Struts//XWork Validator 1.0.3//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
<validators>
<fieldname="name">
<field-validatortype="requiredstring">
<message>You must enter Your Name</message>
</field-validator>
</field>
<fieldname="emailid">
<field-validatortype="requiredstring">
<message>You must enter Your Emil-ID</message>
</field-validator>
</field>
<fieldname="contactno">
<field-validatortype="regex">
<paramname="regex"><![CDATA[\d{10}]]></param>
<message>Phone number must be entered as 9999999999.</message>
</field-validator>
</field>
</validators>
Registration.jsp
<%@pagelanguage="java"contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglibprefix="s"uri="/struts-tags"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD HTML 4.01
Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html; charset=ISO-8859-1">
<title>Registration</title>
<linkrel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<s:formaction="register"method="post">
<s:textfieldlabel="Username "name="name"/>
<s:textfieldlabel="Email-ID "name="emailid"/>
<s:textfieldlabel="Contact No "name="contactno"/>
<s:submitvalue="Submit"/>
</s:form>
</div>
</body>
</html>
Welcome.jsp
<%@pagelanguage="java"contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglibprefix="s"uri="/struts-tags"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD HTML 4.01
Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Welcome</h1>
Hello: <s:propertyvalue="name"/>
Your Email-ID: <s:propertyvalue="emailid"/>
Your Contact No: <s:propertyvalue="contactno"/>
</body>
</html>
OutPut:
FAQs:
1. What are the components of Struts Framework?
2. Which file is used by controller to get mapping information for request routing?
3. What’s the role of Action Class in Struts?
4. What’s the purpose of Execute method of action class?
5. What are the benefits of Struts framework?
6. What is Struts2?
7. What are the differences between Struts1 and Struts2 or how Struts2 is better than Struts1?
8. What is the difference in using Action interface and ActionSupport class for our action
classes, which one you would prefer?
Assignment No: 9
Problem Statement: Design an application using Angular JS.
Objectives: To use web technology languages, frameworks and services.
Outcome: Analyze the web technology languages, frameworks and services
Software & Hardware Requirments:
Operating System: Ubuntu
Software: Gedit
Programming Language: Angular JS
Server: Wamp
Browser: Mozilla/Google Chrome
Hardware: i3 Processor, 4GB RAM, 500GB HDD
Theory:
1. Introduction
AngularJS is an open-source web application framework. It was initially created in 2009 by
MiskoHevery and Adam Abrons. It is presently kept up by Google. Its most recent adaptation
is 1.2.21. "AngularJS is an auxiliary system for dynamic web applications. It gives you a
chance to utilize HTML as your layout dialect and gives you a chance to stretch out HTML's
linguistic structure to express your application parts plainly and compactly. Its information
official and reliance infusion take out a significant part of the code you as of now need to
compose. Also, everything occurs inside the program, making it a perfect band together with
any server innovation".
General Features
∙ AngularJS is a productive system that can make Rich Internet Applications (RIA).
∙ AngularJS gives designers a choices to compose customer side applications utilizing
JavaScript in a spotless Model View Controller (MVC) way.
∙ Applications written in AngularJS are cross-program agreeable. AngularJS
consequently handles JavaScript code reasonable for every program.
∙ AngularJS is open source, totally free, and utilized by a great many engineers the
world over. It is authorized under the Apache permit version2.0.
∙ By and large, AngularJS is a system to assemble expansive scale, elite, and simple to
keep up web applications.
AngularJS is a JavaScript framework. It can be added to an HTML page with a <script> tag.
AngularJS extends HTML attributes with Directives, and binds data to HTML with
Expressions.
<scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angul
ar.min.js"></script>
<div ng-app="">
AngularJS expressions bind AngularJS data to HTML the same way as the ng-binddirective.
<!DOCTYPE html>
<html>
<scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angul
ar.min.js"></script>
<body>
<div ng-app="">
<p>Name: <input type="text" ng-model="name"></p>
<p>{{name}}</p>
</div>
</body>
</html>
2. AngularJS Expressions
Expressions are used to bind application data to html. Expressions are written inside double
braces like {{ expression}}. Expressions behaves in same way as ng-bind directives.
AngularJS application expressions are pure javascript expressions and outputs the data where
they are used.
<!DOCTYPE html>
<html>
<scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angul
ar.min.js"></script>
<body>
<div ng-app="">
<p>My first expression: {{ 5 + 5 }}</p>
</div>
</body>
</html>
If you remove the ng-app directive, HTML will display the expression as it is, without
solving it.
You can write expressions wherever you like, AngularJS will simply resolve the expression
and return the result.
Example: Let AngularJS change the value of CSS properties. Change the color of the input
box below, by changing its value.
<div ng-app="" ng-init="myCol='lightblue'">
<input style="background-color:{{myCol}}" ng-model=
"myCol" value="{{myCol}}">
</div>
3. AngularJS Modules
An AngularJS module defines an application.
The module is a container for the different parts of an application.
The module is a container for the application controllers.
Controllers always belong to a module.
The "myApp" parameter refers to an HTML element in which the application will run. Now
you can add controllers, directives, filters, and more, to your AngularJS application.
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"
></script>
<body>
</div>
<script>
app.controller("myCtrl", function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
});
</script>
</body>
</html>
4. AngularJS Controllers
AngularJS application mainly relies on controllers to control the flow of data in the
application. A controller is defined using ng-controller directive. A controller is a JavaScript
object ontaining attributes/properties and functions. Each controller accepts $scope as a
parameter which refers to the application/module that controller is to control.
<html>
<head>
<title>Angular JS Controller</title>
<script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>
</head>
<body>
<br>
</div>
<script>
mainApp.controller('studentController', function($scope) {
$scope.student = {
firstName: "Mahesh",
lastName: "Parashar",
fullName: function() {
var studentObject;
studentObject = $scope.student;
};
});
</script>
</body>
</html>
Conclusion:
Hence, we have successfully designed a web application using Angular JS.
Program
1. Userhome.html
<!DOCTYPE html>
<html>
<style>
table, th , td
border-collapse: collapse;
padding: 5px;
align: center;
table tr:nth-child(odd)
background-color: #f1f1f1;
table tr:nth-child(even)
background-color: #ffffff;
</style>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.m
in.js"></script>
<body>
<table>
<tr>
<th>Qualification</th>
<th>Course</th>
<th>Duration</th>
</tr>
</tr>
</table>
</div>
</center>
<script>
$http.get("course.php")
.then(function (response)
{$scope.names = response.data.records;});
});
</script>
</body>
</html>
2. course.php
{ "records":[
{"qual":"SSC","course":"MSCIT","duration":"3 months"},
{"qual":"SSC","course":"DTP","duration":"3 months"},
{"qual":"HSC","course":"HTML","duration":"1 months"},
{"qual":"Diploma","course":"OCJP","duration":"3 months"},
{"qual":"Diploma","course":"CCNA","duration":"3 months"},
] }
Output:
Userhome page
FAQs:
1. What is AngularJS and what are some of its advantages?
2. What is the Model View Controller (MVC)?
3. What is data binding in AngularJS? How does it relate to the MVC architecture?
4. Explain the concept of scope. How does scope inheritance work in AngularJS?
5. Explain the difference between a factory and a service in AngularJS?
6. Explain why there are two “destroy” events associated with the termination of a scope in
AngularJS?
7. What is dependency injection and how does it work?
8. What are directives? Can you explain the functions of the following directives?
9. Explain the role of $routeProvider in AngularJS?
Assignment No: 10
Problem Statement: Design and implement a business interface with necessary
business logic for any web application using EJB.
Objectives: To design and develop web applications using front end technologies
and backend databases.
Outcome: Create three tier web based applications
Software & Hardware Requirments:
Operating System: Ubuntu
Software: Eclipse
Programming Language: Java
Server: Tomcat
Browser: Mozilla/Google Chrome
Hardware: i3 Processor, 4GB RAM, 500GB HDD
Theory:
1. Introduction
EJB stands for Enterprise Java Beans. EJB is an essential part of a J2EE platform. J2EE
platform has component based architecture to provide multi-tiered, distributed and highly
transactional features to enterprise level applications. EJB provides an architecture to develop
and deploy component based enterprise applications considering robustness, high scalability,
and high performance. An EJB application can be deployed on any of the application server
compliant with the J2EE 1.3 standard specification.
1.1Types
EJB is primarily divided into three categories; following table lists their names with brief
descriptions −
S.No Type & Description
1 Session Bean
Session bean stores data of a particular user for a single session. It can
be stateful or stateless. It is less resource intensive as compared to entity bean. Session bean
gets destroyed as soon as user session terminates.
2 Entity Bean
Entity beans represent persistent data storage. User data can be saved to database via entity
beans and later on can be retrieved from the database in the entity bean.
1.3 Benefits
Following are the important benefits of EJB −
● Simplified development of large-scale enterprise level application.
● Application Server/EJB container provides most of the system level services like
transaction handling, logging, load balancing, persistence mechanism, exception
handling, and so on. Developer has to focus only on business logic of the application.
● EJB container manages life cycle of EJB instances, thus developer needs not to worry
about when to create/delete EJB objects.
You will see an EJB project in the Project Explorer view as shown below.
Right click on this package and Create a new Interface and name it to Hello and click Finish
Interface can be either @Remote or @Local or without any annotation. In this example we
have used @Remote .
Add following code into this Interface.
Hello.java
package com.jwt.ejb.business;
import javax.ejb.Remote;
@Remote
Create a new package by Right click on ejbModule -> New -> Package and name this
package to com.jwt.ejb.businesslogic and click on Finish.
Create a new Class HelloBean in this package which should implement Hello interface and
add the following code.
This is a Bean class. Bean type can either be @Stateful or @Stateless . In this example we
have used @Stateless .
Hello.java
package com.jwt.ejb.businesslogic;
import javax.ejb.Stateless;
import com.jwt.ejb.business.Hello;
@Stateless
public HelloBean() {
Context.URL_PKG_PREFIXES = org.jboss.naming:org.jnp.interfaces<br>
Context.PROVIDER_URL = jnp://localhost:1099
Client.java
package com.jwt.ejb.test;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.jwt.ejb.business.Hello;
public class Client {
public static void main(String[] args) {
Hello bean = doLookup();
System.out.println(bean.sayHello()); // 3. Call business logic
}
private static Hello doLookup() {
Context context = null;
Hello bean = null;
try {
// 1. Obtaining Context
context = getInitialContext();
// 2. Lookup and cast
bean = (Hello) context.lookup(LOOKUP_STRING);
} catch (NamingException e) {
e.printStackTrace();
}
return bean;
}
private static final String LOOKUP_STRING = "HelloBean/remote";
private static final String PROVIDER_URL = "jnp://localhost:1099";
private static final String JNP_INTERFACES = "org.jboss.naming:org.jnp.interfaces";
private static final String INITIAL_CONTEXT_FACTORY = "org.jnp.interfaces.NamingConte
private static Context initialContext;
public static Context getInitialContext() throws NamingException {
if (initialContext == null) {
// Properties extends HashTable
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
prop.put(Context.URL_PKG_PREFIXES, JNP_INTERFACES);
prop.put(Context.PROVIDER_URL, PROVIDER_URL);
initialContext = new InitialContext(prop);
}
return initialContext;
}
}
If the project is deployed properly with global JNDI mapping then you will see the
following message in the console.
Conclusion:
Hence, we have successfully designed and implement a EJB Application.
FAQs:
1. What is EJB?
2. What are the types of Enterprise Bean?
3. What is stateless session bean?
4. Write down the steps for the creation of stateless EJB.
5. What is JMS?
6. What is Entity Bean?
Assignment No: 11
Problem Statement: Mini Project: Design and implement a dynamic web
application for any business functionality by using web development technologies
that you have learnt in the above given assignments.
Objectives: To design and develop web applications using front end technologies
and backend databases.
Outcome: Create three tier web based applications
Software & Hardware Requirments:
Operating System: Ubuntu
Software: Eclipse
Programming Language: Java
Server: Tomcat
Browser: Mozilla/Google Chrome
Hardware: i3 Processor, 4GB RAM, 500GB HDD
1. Servlet
Java Servlets are programs that run on a Web or Application server and act as a
middle layer between a request coming from a Web browser or other HTTP client and
databases or applications on the HTTP server. Using Servlets, you can collect input from
users through web page forms, present records from a database or another source, and create
web pages dynamically. Java Servlets often serve the same purpose as programs implemented
using the Common Gateway Interface (CGI).
// Initialization code...
// Finalization code...
1.3 Examples
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Do required initialization
response.setContentType("text/html");
// do nothing.
2. JavaServer Pages.
JavaServer Pages (JSP) is a technology for developing web pages that support
dynamic content which helps developers insert java code in HTML pages by making use of
special JSP tags, most of which start with <% and end with %>.
A JavaServer Pages component is a type of Java servlet that is designed to fulfill 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 embedded JSP actions and
commands.
Using JSP, you can collect input from users through web page forms, present records
from a database or another source, and create web pages dynamically.
JSP tags can be used for a variety of 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.
JSP Processing:
The following steps explain how the web server creates the web page using JSP:
● As with a normal page, your browser sends an HTTP request to the web server.
● The web server recognizes that the HTTP request is for a JSP page and forwards it to
a JSP engine. This is done by using the URL or JSP page which ends with .jsp instead
of .html.
● The JSP engine loads the JSP page from disk and converts it into a servlet content.
This conversion is very simple in which all template text is converted to println( )
statements and all JSP elements are converted to Java code that implements the
corresponding dynamic behavior of the page.
● The JSP engine compiles the servlet into an executable class and forwards the original
request to a servlet engine.
● A part of the web server called the servlet engine loads the Servlet class and executes
it. During execution, the servlet produces an output in HTML format, which the
servlet engine passes to the web server inside an HTTP response.
● The web server forwards the HTTP response to your browser in terms of static HTML
content.
● Finally web browser handles the dynamically generated HTML page inside the HTTP
response exactly as if it were a static page.
● All the above mentioned steps can be shown below in the following diagram:
// Initialization code...
Typically initialization is performed only once and as with the servlet init method,
you generally initialize database connections, open files, and create lookup tables in the
jspInit method.
HttpServletResponse response)
The _jspService() method of a JSP is invoked once per a request and is responsible
for generating the response for that request and this method is also responsible for generating
responses to all seven of the HTTP methods ie. GET, POST, DELETE etc.
Any text, HTML tags, or JSP elements you write must be outside the scriptlet.
Following is the simple and first example for JSP:
<html>
<head><title>Hello World</title></head>
<body>
Hello World!<br/>
<%
%>
</body>
</html>
</jsp:expression>
<body>
</body>
</html>
context.
config This is the ServletConfig object associated with the page.
This encapsulates use of server-specific features like higher
pageContext
performance JspWriters.
This is simply a synonym for this, and is used to call the
page
methods defined by the translated servlet class.
The Exception object allows the exception data to be accessed
Exception
by designated JSP.
Conclusion:
Hence, we have successfully designed and implement a Mini Project.
Program:
Project Structure
1. style.css
body
background-image: url("img.jpeg");
background-repeat: no-repeat;
background-size: cover;
.login
border-radius: 5px;
height: 200px;
width: 310px;
border-color:#3498DB;
padding-top: 20px;
.register
border-radius: 5px;
height: 350px;
width: 310px;
border-color:#3498DB;
padding-top: 20px;
input[type="password"], input[type="text"]
border:1px solid;
background-color:rgba(0,0,0,0.0);
height: 33px;
width:240px;
padding-left: 10px;
input[type="submit"]
background-color: #4CAF50;
color: white;
height: 42px;
width: 250px;
padding-left: 10px;
input[type="submit"]:hover
background-image: linear-gradient(#4ec7c0,#31aba3)
input[type="submit"]:active
padding: 0;
2. index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
<div class="login">
<label><b>Username</b></label>
<label><b>Password</b></label>
</form>
</div>
</body>
</html>
3. DBConnection.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
boolean flag=false;
try
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/tecomp","roo
t","root");
Statement stmt=con.createStatement();
while(rs.next())
String Dpass=rs.getString("password");
flag=true;
break;
con.close();
catch (Exception e)
e.printStackTrace();
if(flag==true)
return true;
else
return false;
4. LoginValidate.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/LoginValidate")
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String UserName=request.getParameter("username");
String Password=request.getParameter("password");
//out.println("Username :"+UserName);
//out.println("<br>Pass:"+Password);
if(d.verify(UserName, Password))
RequestDispatcher
rd=request.getRequestDispatcher("Home.jsp");
rd.forward(request, response);
else
out.println("<b><center>Username or Password is
Wrong Please Retry</center></b>");
RequestDispatcher
rd=request.getRequestDispatcher("index.html");
rd.include(request, response);
5. Home.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
</head>
<body>
<table border="1">
<tr>
<th>Qualification</th>
<th>Intrest</th>
<th>Course Suggestion</th>
</tr>
<tr>
<td>12th</td>
<td>Programming</td>
<td>C,C++</td>
</tr>
<tr>
<td>12th</td>
<td>Web Design</td>
<td>HTML,CSS,JavaScript</td>
</tr>
<tr>
<td>12th</td>
<td>Car Design</td>
<td>AutoCAD, CATIA</td>
</tr>
<tr>
<td>12th</td>
<td>Robotics</td>
</tr>
</table>
</center>
</body>
</html>
6. Register.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
</head>
<body>
<div class="register">
<label><b>Username</b></label>
<br> <label><b>Password</b></label>
<br><label><b>Mobile Number</b></label>
<br><label><b>E-Mail Address</b></label>
<br><label><b>Age</b></label>
</form>
</body>
</html>
7. addDataTodatabase.jsp
<%@page import="java.sql.*"%>
pageEncoding="UTF-8"%>
<html>
<head>
</head>
<body>
<%
boolean flag=false;
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost/tecomp","roo
t","root");
Statement stmt=con.createStatement();
if(i>0)
response.sendRedirect("index.html");
%>
</body>
</html>
Output:
1. Login Page
2. Home Page
3. Registration Page
4. Database
FAQs:
1. What is JSP?
2. What is Servlet?
3. What is the purpose of MySQL?
4. What is database?
5. What is the syntax of JSP?
6. How do we connect JSP file to database?
7. Explain life cycle of servlet?
8. What is session management?
9. Explain advantages of JSP over Servlet?
10. Explain Scriptlet, Expression, Declaration tag in JSP?
11. List default object in JSP?