Mean Stack Technologies - Lab Manual
Mean Stack Technologies - Lab Manual
LAB MANUAL
I M. Tech II SEMESTER
REGULATION – NRIA23
LIST OF PROGRAMS
Experiment-1:
Develop static pages (using only HTML) of an online Book store. The pages should resemble:
www.amazon.com. The website should consist of the following pages. Home page
Registration and user Login
User profile page
Books catalog
Shopping cart
Payment by credit card Order Conformation
Experiment-2:
Write an HTML page including any required JavaScript that takes a number from text field in the range of 0 to 999
and shows it in words. It should not accept four and above digits, alphabets and special characters.
Experiment-3:
Develop and demonstrate JavaScript with POP-UP boxes and functions for the following problems:
a) Input: Click on Display Date button using on click ( ) function Output: Display date in the textbox
b) Input: A number n obtained using prompt Output: Factorial of n number using alert
c) Input: A number n obtained using prompt Output: A multiplication table of numbers from 1 to 10 of n using alert
d) Input: A number n obtained using prompt and add another number using confirm Output: Sum of the entire n
numbers using alert
Experiment-4:
Create a simple visual bean with a area filled with a color. The shape of the area depends on the property shape. If it
is set to true then the shape of the area is Square and it is Circle, if it is false. The color of the area should be changed
dynamically for every mouse click.
Experiment-5:
Create an XML document that contains 10 users information. Write a Java Program, which takes User Id as input
and returns the user details by taking the user information from XML document using DOM parser or SAX parser.
Experiment-6:
Develop and demonstrate PHP Script for the following problems:
a) Write a PHP Script to find out the Sum of the Individual Digits.
b) Write a PHP Script to check whether the given number is Palindrome or not
Experiment-7:
Implement the following in CSS
a) Implementation of ‘get’ and ‘post’ methods.
Experiment-1:
Develop static pages (using Only HTML) of an online Book store. The pages should resemble:
www.amazon.com The website should consist the following pages.
Home page,
Registration and user Login
User Profile Page,
Books catalog
Shopping Cart,
Payment By credit card
Order Conformation.
Home page
Main.html:
<html>
<head>
<title>
Amazon</title>
</head>
<body bgcolor="cyan"> <center>
<strong><h1>Welcome to AMAZON</h1></strong>
<form method="post" action="login.html" target=_blank >
<h4>for books</h4><input type="submit" value="click here">
</form>
</center>
</body>
</html>
</tr>
<tr>
<td><h4>password</td>
<td><input type="password"></td>
<td></td>
</tr>
<tr>
<td>
<form method="post" action="catalog.html" >
<input type="submit" value="submit" >
</form>
</td>
<td>
<form method="post" action="reg.html" >
<input type="submit" value="register" >
<input type="reset" value="reset"></form></td>
</tr>
</table>
</body>
</html>
Registration page
reg.html:
<html>
<head>
<title>
login page</title>
</head>
<body bgcolor="cyan">
<center><strong><h1> AMAZON </h1></strong></center>
<form method="post" action="catalog.html" >
<right>
<table align="left">
<tr>
<td><h4>user name</td>
<td><input type="text" ></td>
<tr>
<tr>
<td><h4>password</td>
<td><input type="password"></td>
</tr>
<tr>
<td><h4>confirm password</td>
<td><input type="password"></td>
</tr>
<tr>
<td><h4>male
<option >
<input type="radio" name="sex" id="male"></td>
<td><h4>female
<td>Address</td>
<td><textarea name="address" rows=5 cols=19>
</textarea>
</td>
<tr>
<td>
<input type="submit" value="submit" ></td>
<td>
<input type="reset" value="reset"></td>
</tr>
</form>
</body>
</html>
Userprofile
userprofile.html
<html>
<head>
<title>
userprofile</title>
</head>
<body bgcolor="cyan"> <center>
<strong><h1>Welcome to AMAZON Online Book Store </h1></strong></center>
Edit your profile here...
<form method="post" action="catalog.html" >
<right>
<table align="left">
<tr>
</tr>
<tr>
<td>Edit Address</td>
<td><textarea name="address" rows=5 cols=19>
</textarea>
</td>
<tr>
<td>
<input type="submit" value="submit" ></td>
</tr>
</form>
</body>
</html>
Books catalog
Catalog.html:
<html>
<head>
<title>
books catalog</title>
</head>
<body bgcolor="cyan">
<center><h1>AMAZON</h1></center>
<form method="post" action="shopping.html">
<left>
<table>
<tr>
<td><b><h3>frontend books</td>
<td></td></tr>
<tr>
<td></td>
<td><h4>C&Ds</td>
</tr>
<tr>
<td></td>
<td><h4>Ads</td>
</tr>
<tr>
<td></td>
<td><h4>JAVA
</td></tr>
<tr>
<td><b><h3>backend books</td>
<td></td>
</tr>
<tr>
<td></td>
<td><h4>Oracle</td>
</tr>
<tr>
<td></td>
<td><h4>Ms SQL Server
</td></tr>
<tr>
<td></td>
<td><h4>MySql </td>
</tr>
</table>
</h4>
<center>
<b>for buy one of these books
<br>
</b><input type="submit" value="click here">
</center>
</form>
</body>
</html>
Shopping cart
Shopping.html:
<html>
<head><title>shopping cart</title>
</head>
<body bgcolor="cyan">
<center><h1>
Shopping Cart</h1></center>
<br><br><br><br><br>
<table align="center">
<tr>
<td>Text Books</td>
<td>
<select >
<optgroup label="select the book">
<option value="C&Ds">C&Ds
<option value="Ads">Ads
<option value="Java">Java
<option value="Oracle">Oracle
<option value="Ms SQL Server">Ms SQL Server
<option value="MySql">MySql
</optgroup>
</select>
</td></tr>
<tr>
<td>
Quantity</td>
<td>
<input type="text" id="q">
</td></tr>
<tr>
<td></td>
<td>
<form method=post action="payment.html">
<input type="submit" value=ok />
</form>
</td></tr>
</table>
<center>
<pre>Cost of one book is"500" + shipping "100"</pre>
</center>
<body>
</html>
Order Conformation
Ordrconform:
<html>
<head><title>order conformation</title><M/head>
<body bgcolor="cyan">
<center>
<h1><b>BOOK SHOPPING</h1>
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center>
</body></html>
output:
Experiment-2:
Write an HTML page including any required JavaScript that takes a number from text field in the range of 0
to 999 and shows it in words. It should not accept four and above digits, alphabets and special characters.
AIM: To convert number to words using JavaScript
PROGRAM:
0-999.html
<html>
<head>
<title>HTML - Convert numbers to words using JavaScript</title>
<SCRIPT language=Javascript>
<!--
function isNumberKey(evt)
{
if (rev[i] == 0) {
word[j] = '';
}
else if ((rev[i - 1] == 0) || (rev[i - 2] == 0)) { word[j] = once[rev[i]] + " Hundred ";
}
else {
word[j] = once[rev[i]] + " Hundred and";
}
break; default: break;
}
j++;
}
function aboveTens() {
if (rev[i] == 0) { word[j] = ''; }
else if (rev[i] == 1) { word[j] = twos[rev[i - 1]]; } else { word[j] = tens[rev[i]]; }
}
word.reverse();
var finalOutput = '';
for (i = 0; i < numLength; i++) { finalOutput = finalOutput + word[i];
}
document.getElementById(outputControl).innerHTML = finalOutput;
</script>
</head>
<body>
<h1>HTML - Convert numbers to words using JavaScript</h1>
<input id="Text1" type="text" onkeypress="return isNumberKey(event)"
onkeyup="NumToWord(this.value,'divDisplayWords');" maxlength="3" style="background- color: #efefef; border:
2px solid #CCCCC; font-size: large" />
<br /> <br />
<div id="divDisplayWords" style="font-size: 30; color: Teal; font-family: Arial;">
</div>
</body>
</html>
Output
Experiment-3:
Develop and demonstrate JavaScript with POP-UP boxes and functions for the following problems:
a) Input: Click on Display Date button using on click ( ) function Output: Display date in the textbox
b) Input: A number n obtained using prompt Output: Factorial of n number using alert
c) Input: A number n obtained using prompt Output: A multiplication table of numbers from 1 to 10 of n
using alert
d) Input: A number n obtained using prompt and add another number using confirm Output: Sum of the
entire n numbers using alert
PROGRAM:
a) date.html
<html>
<body>
<script>
function display(){
var x="You have clicked"; var d=new Date();
var date=d.getDate();
var month=d.getMonth(); month++;
var year=d.getFullYear(); document.getElementById("dis").value=date+"/"+month+"/"+year;
}
</script>
<form>
<input type="text" id="dis" /><br />
<input type="button" value="Display Date" onclick="display()" />
</form>
<body>
</html>
OUTPUT:
b) factorial.html
<html>
<head>
<title>factorial</title>
<script language='javascript'>
function factorialcalc()
{
number = parseint(prompt("enter a number, i'll calculate its factorial", "whole numbers bigger than zero,
please"))
factorial = 1
for (i=1; i <= number; i++)
{
factorial = factorial * i
}
alert("the factorial of " + number + " is " + factorial)
}
</script>
</head>
<body><form name=frm>
<input type=button value='factorial' onclick="factorialcalc();">
</form>
</body>
</html>
c) mutable.html
<html>
<head><title> Multiplication Table </title></head>
<body>
<script type="text/javascript">
<!--
var n=prompt("Enter positive value for n: "," "); if(!isNaN(n)) {
var table=""; var number="";
for(i=1;i<=10;i++) {
number = n * i;
table += n + " * " + i + " = " + number + "\n";
else {
} }alert(table);}
alert("Enter positive value"); n=prompt("Enter positive value for n: "," ");
document.write(n+" table values displayed using alert ..<br />");
// --></script>
</body></html>
d) sum of n numbers.html
<html>
<head><title>sum of n numbers using popup boxes</title>
<script language='javascript'> function addsum(){
alert("you're going to give me a list of numbers. i'm going to add them together for you"); var keepgoing = true
var sumofnums = 0 while (keepgoing) {
sumofnums = sumofnums + parseint(prompt("what's the next number to add?","")) keepgoing = confirm("add
another number?")
}alert("the sum of all your numbers is " + sumofnums)
}
</script>
</head>
<body>
<form name=frm>
<input type=button value='sum of n numbers' onclick="addsum();">
</form>
</body>
</html>
Experiment-4:
NRI Institute of Technology 19 | P a g e
I M.Tech II Sem CSE Lab Manual
Create a simple visual bean with a area filled with a color. The shape of the area depends on the property
shape. If it is set to true then the shape of the area is Square and it is Circle, if it is false. The color of the
area should be changed dynamically for every mouse click
Aim
VISUAL BEANS:
Create a simple visual bean with a area filled with a color.
The shape of the area depends on the property shape. If it is set to true then the shape of the area is Square
and it is Circle, if it is false.
The color of the area should be changed dynamically for every mouse click. The color should also be
The constructor defines an anonymous inner class that extends MouseAdapter and overrides its mousePressed( )
method. The change( ) method is invoked in response to
mouse presses. The component is initialized to a rectangular shape of 200 by 100 pixels.
The change( ) method is invoked to select a random color and repaint the component.
The getRectangular( ) and setRectangular( ) methods provide access to the one
property of this Bean. The change( ) method calls randomColor( ) to choose a color and
then calls repaint( ) to make the change visible. Notice that the paint( ) method uses the
rectangular and color variables to determine how to present the Bean.
Compile the Source Code for the New Bean
Compile the source code to create a class file. Type the following:
javac Colors.java.
Create a Manifest File
You must now create a manifest file. First, switch to the z:\WtLab\week7 directory. This is
the directory in which the manifest files for the BDK demos are located. Put the source
code for your manifest file in the file colors.mft. It is shown here:
Name: Colors.class
Java-Bean: True
This file indicates that there is one .class file in the JAR file and that it is a Java Bean.
Generate a JAR File
Beans are included in the ToolBox window of the BDK only if they are in JAR files in the
directory z:\WtLab\week7. These files are generated with the jar utility. Enter the following:
jar cfm Colors.jar Colors.mft *.class
This command creates the file colors.jar and places it in the directory z:\WtLab\week7
Start the BDK
Change to the directory BDK and run run.bat. This causes the BDK to start.
You should see three windows, titled ToolBox, BeanBox, and Properties. The ToolBox
window should include an entry labeled "Colors" for your new Bean.
Create an Instance of the Colors Bean
After you complete the preceding steps, create an instance of the Colors Bean in the
BeanBox window. Test your new component by pressing the mouse anywhere within its
borders. Its color immediately changes. Use the Properties window to change the
rectangular property from false to true. Its shape immediately changes.
Source Code
Colors.java
import java.awt.*;
import java.awt.event.*;
public class Colors extends Canvas {
transient private Color color;
private boolean rectangular;
public Colors() {
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent me) {
change();
}
});
rectangular = false;
setSize(200, 100);
change();
}
repaint();
}
public void change() {
color = randomColor();
repaint();
}
private Color randomColor() {
int r = (int)(255*Math.random());
int g = (int)(255*Math.random());
int b = (int)(255*Math.random());
return new Color(r, g, b);
}
public void paint(Graphics g) {
Dimension d = getSize();
int h = d.height;
int w = d.width;
g.setColor(color);
if(rectangular) {
g.fillRect(0, 0, w-1, h-1);
}
else {
g.fillOval(0, 0, w-1, h-1);
}
}
}
Colors.mft
Name: Colors.class
Java-Bean: True
Creation of jar file:
Z:\ jar cfm Colors.jar Colors.mft *.class
Now the jar file is created .
Execution procedure
1. Write the source program in the notepad and save it as Colors.java
2. Complile the java file as follows
javac Colors.java
now two .class files are created
3. create the manifest file with the following code
Name: Colors.class
Java-Bean: true
Save it as Colors.mft
4. create the jar file for by the following syntax
Z:\ jar cfm Colors.jar Colors.mft *.class
5. now the jar file is created so we can open the bdk/beanbox/run.bat
then load the jar file .. it can be shown in the tools box..
now we can select the Colors bean and place it on the bean box...
6. we click the ovel it can change the colors.. and click the rectangular is true then it
changes to the rectangle.....
Experiment-5:
Create an XML document that contains 10 users information. Write a Java Program, which takes User Id as input
and returns the user details by taking the user information from XML document using DOM parser or SAX parser.
<?xml version="1.0" encoding="UTF-8"?>
<students-details>
<student>
<studentid>561</studentid>
<name>Ramu</name>
<address>ECIL</address>
<gender>Male</gender>
</student>
<student>
<studentid>562</studentid>
<name>Ramya</name>
<address>KBHP</address>
<gender>Female</gender>
</student>
<student>
<studentid>563</studentid>
<name>Mahi</name>
<address>BHEL</address>
<gender>Male</gender>
</student>
<student>
<studentid>564</studentid>
<name>Manvi</name>
<address>KOTI</address>
<gender>Female</gender>
</student>
<student>
<studentid>565</studentid>
<name>Ammu</name>
<address>ECIL</address>
<gender>Female</gender>
</student>
</students-details>
SAXParserxml.java
import java.io.*;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class SAXParserxml extends DefaultHandler
{
boolean studentid = true,name = false,address = false,gender = false;
int flag=0,c=0;
String sid,sname,sadd,sgender,tid;
public void startDocument()
{
System.out.println("begin parsing document");
System.out.print("Enter student ID:\t");
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
tid = reader.readLine();
}catch(Exception e){}
}
public void startElement(String url,String localname, String qName, Attributes att){
if (qName.equalsIgnoreCase("studentid"))
{
studentid = true;
}
else if (qName.equalsIgnoreCase("name") && flag==1)
{
name = true;
}
else if (qName.equalsIgnoreCase("address")&& flag==1)
{
address = true;
}
else if (qName.equalsIgnoreCase("gender")&& flag==1)
{
gender = true;
}
}
flag=1;sid=x; c=1;
}
else
flag=0;
studentid = false;
}
else if (name)
{
sname=new String(ch, start, length); name = false;
}
else if (address)
{
sadd=new String(ch, start, length); address = false;
}
else if (gender)
{
sgender=new String(ch, start, length); gender = false;
}
}
public void endElement(String url,String localname, String qName){}
public void endDocument()
{
if(c==0)
System.out.println("student Id is not present.Try Again!!!");
else
{
System.out.println("\n\n STUDENT-DETAILS");
System.out.println("===================");
System.out.println("student id :\t" +sid);
System.out.println("student Name :\t" +sname);
System.out.println("Adress :\t" +sadd);
System.out.println("Gender :\t" +sgender);
}
}
public static void main(String[] arg)throws Exception{
SAXParser p=SAXParserFactory.newInstance().newSAXParser();
p.parse(new FileInputStream("student.xml"), new SAXParserxml());
}
}
Output:
SAXParserxml.java
import java.io.*;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class SAXParserxml extends DefaultHandler
studentid = false;
}
else if (name)
{
sname=new String(ch, start, length); name = false;
}
else if (address)
{
sadd=new String(ch, start, length); address = false;
}
else if (gender)
{
sgender=new String(ch, start, length); gender = false;
}}
public void endElement(String url,String localname, String qName){}
public void endDocument()
{
if(c==0)
System.out.println("student Id is not present.Try Again!!!");
else{
System.out.println("\n\n STUDENT-DETAILS");
System.out.println("===================");
System.out.println("student id :\t" +sid);
System.out.println("student Name :\t" +sname);
System.out.println("Adress :\t" +sadd);
System.out.println("Gender :\t" +sgender);
}}
public static void main(String[] arg)throws Exception{
SAXParser p=SAXParserFactory.newInstance().newSAXParser();
p.parse(new FileInputStream("student.xml"), new SAXParserxml());
}}
Output:
Experiment-6:
<?php
$n=323;
$sum=0; while($n>0)
{
$r=$n%10;
$sum+=$r;
$n=$n/10;
}
echo "sum of individual digits are: $sum";
b) Write a PHP Script to check whether the given number is Palindrome or not
<?php
$n=323;
$t=$n;
$rev=0; while($n>0)
{
$r=$n%10;
$rev=$rev*10+$r;
$n=(int)($n/10);
}
echo "Reverse digits are: $rev <br>";
if($t==$rev)
echo "$rev is a Palindrome"; else
echo "$rev is not a Palindrome";
?>
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
border-radius: 4px; /* Rounded corners */
}
button[type="submit"]:hover, input[type="submit"]:hover {
background-color: #45a049; /* Darker green on hover */
}
b) Implementation in colors, border, padding:
/* Example styles for colors, borders, and padding */
/* Colored border */
.element-with-border {
border: 2px solid #ccc; /* Gray border */
padding: 10px; /* Padding inside the element */
}
/* Colored background */
.element-with-background {
background-color: #f0f0f0; /* Light gray background */
padding: 15px; /* Padding inside the element */
}
/* Rounded corners */
.element-with-rounded-corners {
border-radius: 5px; /* Rounded corners */
}
/* Shadow effect */
.element-with-shadow {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); /* Shadow effect */
}
c) Implementation button frames tables, navigation bars:
/* Styling for button frames */
.button-frame {
cursor: pointer;
background-color: #f0f0f0; /* Light gray background */
border-radius: 3px; /* Rounded corners */
}
.button-frame:hover {
background-color: #e0e0e0; /* Darker gray on hover */
}
For tables:
/* Styling for tables */
.table {
width: 100%; /* Full width */
border-collapse: collapse; /* Collapse borders */
}
.table th {
background-color: #f2f2f2; /* Light gray background for header */
}
.table tr:hover {
background-color: #f1f1f1; /* Light gray on hover */
}
Implement the following web applications using (a) PHP, (b) Servlets and (c) JSP.
6.1 A user validation web application, where the user submits the login name and password to the server. The name
and password are checked against the data already available in Database and if the data matches, a successful login
page is returned. Otherwise a failure message is shown to the user.
Aim: User Authentication:
cologin.html:
<html>
<head>
<title> login Page </title>
<p style= "background:yellow; top:100px; left:250px; position:absolute; ">
</head>
<body>
<form ACTION="clogin">
<label> Login </label>
<input type="text" name="usr" size="20"> <br> <br>
Addcook.java:
import javax.servlet.* ; import javax.servlet.http.*; import java.io.*;
public class Addcook extends HttpServlet
{
String user,pas;
public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html"); PrintWriter out=res.getWriter();
Cookie c1=new Cookie("usr1","mrcet"); Cookie p1=new Cookie("pwd1","122"); Cookie c2=new
Cookie("usr2","abc"); Cookie p2=new Cookie("pwd2","123"); Cookie c3=new Cookie("usr3","def"); Cookie
p3=new Cookie("pwd3","456");
Cookie c4=new Cookie("usr4","mno"); Cookie p4=new Cookie("pwd4","789"); res.addCookie(c1);
res.addCookie(p1); res.addCookie(c2); res.addCookie(p2); res.addCookie(c3); res.addCookie(p3);
res.addCookie(c4); res.addCookie(p4); out.println("COOKIE ADDED");
}
}
Clogin.java:
import javax.servlet.* ; import javax.servlet.http.*; import java.io.*;
public class Clogin extends HttpServlet
{
String user,pas;
public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html"); PrintWriter out=res.getWriter(); user=req.getParameter("usr");
pas=req.getParameter("pwd"); Cookie[] c=req.getCookies(); for(int i=0;i<c.length;i++)
{
if((c[i].getName().equals("usr1")&&c[i+1].getName().equals("pwd1"))||
c[i].getName().equals("usr2") &&c[i+1].getName().equals("pwd2"))||
(c[i].getName().equals("usr3")&& c[i+1].getName().equals("pwd3"))||
(c[i].getName().equals("usr4")&& c[i+1].getName().equals("pwd4") ))
{
if((user.equals(c[i].getValue()) && pas.equals(c[i+1].getValue())) )
{
//RequestDispatcher rd=req.getRequestDispatcher("/cart.html"); rd.forward(req,res);
}
else
{
out.println("YOU ARE NOT AUTHORISED USER ");
//res.sendRedirect("/cookdemo/cologin.html");
}
}
}}}
Web.xml:
<web-app>
<servlet>
<servlet-name>him</servlet-name>
<servlet-class>Clogin</servlet-class>
</servlet>
<servlet>
<servlet-name>him1</servlet-name>
<servlet-class>Addcook</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>him</servlet-name>
<url-pattern>/clogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>him1</servlet-name>
<url-pattern>/clogin1</url-pattern>
</servlet-mapping>
</web-app>
OUTPUT:
Experiment-9:
Write a program to design a simple calculator using
a) JavaScript
b) PHP
c) Servlet and
d) JSP.
AIM: A simple calculator application that takes two numbers and an operator (+,-,*,/,%) from an HTML page and
returns the result page with the operation performed on the operands.
Calculator.html (HTML with JavaScript)
<html>
<head>
<title>Arithmetic operations</title>
</head>
<script type="text/javascript"> function Addition()
{x=parseFloat(calc.value1.value); y=parseFloat(calc.value2.value); z=(x+y);
alert("The Addition result is"+z); calc.value3.value=z
}
function Subtraction()
{
CalculateServlet.html
<html>
<head>
<title>Calculator in servlet</title>
</head>
<body>
<form method="get" action="./CalculateServlet"> Number
1 : <input type="text" name="no1"> <br> Number 2 :
<input type="text" name="no2"> <br> Operator :
<select name="opt">
<option value="a"> + </option>
<option value="s"> - </option>
<option value="m"> * </option>
<option value="d"> / </option>
<option value="mod"> % </option>
</select>
<br>
<input type="submit" value="Go">
</form>
</body>
</html>
CalculateServlet.java
import java.io.*; import
javax.servlet.*;
//import javax.servlet.http.*;
{
public void doPost(HttpServletRequest request,HttpServletResponse response) throws
IOException,ServletException
{
display();
PrintWriter out = response.getWriter();
//out.println("hello");
String n1 = request.getParameter("no1");
String n2 = request.getParameter("no2");
String opt = request.getParameter("opt");
if(opt.equals("a"))
out.println(Integer.parseInt(n1) + Integer.parseInt(n2)); else
if(opt.equals("s"))
out.println(Integer.parseInt(n1) - Integer.parseInt(n2)); else
if(opt.equals("m"))
out.println(Integer.parseInt(n1) * Integer.parseInt(n2)); else
if(opt.equals("d"))
out.println(Integer.parseInt(n1) / Integer.parseInt(n2)); else
if(opt.equals("mod"))
out.println(Integer.parseInt(n1) % Integer.parseInt(n2));
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws
IOException,ServletException
{
doPost(request,response);
}
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app metadata-complete="true">
<display-name>Tomcat Manager Application</display-name>
<description>
A scriptable management web application for the Tomcat Web Server; Manager
lets you view, load/unload/etc particular web applications.
</description>
<servlet>
<servlet-name><strong>CalculateServlet</strong></servlet-name>
NRI Institute of Technology 44 | P a g e
I M.Tech II Sem CSE Lab Manual
<servlet-class><strong>CalculateServlet</strong></servlet-class>
</servlet>
else if($_REQUEST['fvalue']==NULL)
{
echo "<script language=javascript> alert(\"Please Enter First value.\");</script>";
}
else if($_REQUEST['lvalue']==NULL)
{
echo "<script language=javascript> alert(\"Please Enter second value.\");</script>";
}
}
?>
<html>
<body>
<center>
<h1>CALCULATOR IN PHP</h1>
<form>
<table style="border:groove #00FF99">
<tr>
</tr>
<tr>
}
?>
<html>
<body>
<center>
<h1>CALCULATOR IN PHP</h1>
<form>
<table style="border:groove #00FF99">
<tr>
<td style="background-color:aqua; color:red; font-family:'Times New
Roman'">Enter First Number</td>
<td colspan="1">
</tr>
<tr>
<td style="background-color:aqua;color:red">Output = </td>
<td style="color:darkblue"><?php echo $res;?></td>
</tr>
</table>
</form>
</center>
</body>
</html>
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app metadata-complete="true">
<display-name>Tomcat Manager Application</display-name>
<description>
A scriptable management web application for the Tomcat Web Server;
Manager lets you view, load/unload/etc particular web applications.
</description>
<servlet>
<servlet-name><strong>CalculateServlet</strong></servlet-name>
<servlet-class><strong>CalculateServlet</strong></servlet-class>
</servlet>
<!-- Define the Manager Servlet Mapping -->
<servlet-mapping>
<servlet-name><strong>CalculateServlet</strong></servlet-name>
<url-pattern>/<strong>CalculateServlet</strong></url-pattern>
</servlet-mapping>
</web-app>
Experiment-10:
Create registration and login forms with validations using Jscript query.
Registration Form
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<style>
.error {
color: red;
}
</style>
</head>
<body>
<h2>Registration Form</h2>
<form id="registrationForm" onsubmit="return validateForm()">
<label for="username">Username:</label><br>
<input type="text" id="username" name="username" required><br>
<span id="usernameError" class="error"></span><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password" required><br>
<span id="passwordError" class="error"></span><br>
<script>
function validateForm() {
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
var confirmPassword = document.getElementById('confirmPassword').value;
isValid = false;
} else if (password !== confirmPassword) {
confirmPasswordError.innerHTML = "Passwords do not match";
isValid = false;
}
return isValid;
}
</script>
</body>
</html>
Login Form
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Form</title>
<style>
.error {
color: red;
}
</style>
</head>
<body>
<h2>Login Form</h2>
<form id="loginForm" onsubmit="return validateLoginForm()">
<label for="username">Username:</label><br>
<input type="text" id="username" name="username" required><br>
<span id="usernameError" class="error"></span><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password" required><br>
<span id="passwordError" class="error"></span><br>
<input type="submit" value="Login">
</form>
<script>
function validateLoginForm() {
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
var usernameError = document.getElementById('usernameError');
var passwordError = document.getElementById('passwordError');
// Reset errors
usernameError.innerHTML = "";
passwordError.innerHTML = "";
var isValid = true;
// Validation logic
if (username.trim() === "") {
usernameError.innerHTML = "Username is required";
isValid = false;
}
if (password.trim() === "") {
passwordError.innerHTML = "Password is required";
isValid = false;
}
return isValid;
}
</script>
</body>
</html>
Experiment-11:
Jscript to retrieve student information from student database using database connectivity.
Step 1: Install Required Packages
You'll need to install the mysql package for Node.js to connect and interact with MySQL
databases.
Open your terminal and navigate to your project directory. Then, run the following command:
npm install mysql
Step 2: Create Database and Table
Assume you have a MySQL database named university with a table named students. Here's an
example SQL script to create the table:
CREATE TABLE students (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
age INT,
grade FLOAT
);
Step 3: Node.js Script to Retrieve Student Information
Create a JavaScript file (app.js for example) in your project directory and use the following code
to connect to the MySQL database and retrieve student information
// Import required packages
const mysql = require('mysql');
Experiment-12:
Implement the following in React JS
a) Using React Js creating constructs data elements.
b) Using React Js implementations DoM.
Step 1: Setting Up React Environment
First, ensure you have Node.js and npm installed. Then, create a new React project using create-
react-app if you haven't already:
1. Install create-react-app globally (if not already installed):
npm install -g create-react-app
2. Create a new React project:
npx create-react-app react-demo
cd react-demo
3. Step 2: Creating Components and Rendering to DOM
In this example, we'll create a simple student list component and render it to the DOM.
1. Create a new component for student list (StudentList.js):
Create a file named StudentList.js in the src folder of your React project.
// src/StudentList.js
import React from 'react';
const students = [
{ id: 1, name: 'Alice', age: 20, grade: 'A' },
{ id: 2, name: 'Bob', age: 21, grade: 'B' },
{ id: 3, name: 'Charlie', age: 22, grade: 'C' },
];
<h2>Student List</h2>
<ul>
{students.map(student => (
<li key={student.id}>
Name: {student.name}, Age: {student.age}, Grade: {student.grade}
</li>
))}
</ul>
</div>
);
};
function App() {
return (
<div className="App">
<header className="App-header">
<h1>Experiment-12: React JS Example</h1>
</header>
<main>
<StudentList />
</main>
</div>
);
}
Experiment-13:
Implement the following in Angular JS
a) Angular Js data binding.
b) Angular JS directives and Events.
c) Using angular Js fetching data from MySQL.
Experiment-14:
Develop and demonstrate Invoking data using Jscript from Mongo DB.
1. Node.js: Make sure Node.js is installed on your machine. You can download it from
nodejs.org.
2. MongoDB: Ensure you have access to a MongoDB instance. You can use a local
installation or a cloud-based service like MongoDB Atlas..
1. Setup Node.js Environment
mkdir mongodb-demo
cd mongodb-demo
npm init -y
2. Install the MongoDB Node.js driver:
npm install mongodb
3. Create a JavaScript file (e.g., index.js) with the following code to connect to MongoDB and
retrieve data:
const { MongoClient } = require('mongodb');
// Connection URL
const url = 'mongodb://localhost:27017'; // Change this to your MongoDB URL
const client = new MongoClient(url);
// Database Name
const dbName = 'mydatabase'; // Replace with your database name
const db = client.db(dbName);
const collection = db.collection('mycollection'); // Replace with your collection name
Experiment-15:
Create an Online fee payment form using JSCript and MangoDB.
To create an online fee payment form using JavaScript and MongoDB, you'll need a basic setup
involving:
1. Front-end: HTML and JavaScript for the form.
2. Back-end: Node.js with Express to handle form submissions and interact with MongoDB.
Prerequisites
Node.js and npm installed on your machine.
Access to a MongoDB database (local or cloud-based).
Steps to Create the Online Fee Payment Form
Step 1: Set Up the Node.js Project
1. Initialize the Project:
mkdir fee-payment
cd fee-payment
npm init -y
2. Install Required Packages:
npm install express mongodb body-parser
Step 2: Create the Front-end Form
Create an index.html file with the following content:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Online Fee Payment</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 0 auto;
padding: 20px;
}
form {
display: flex;
flex-direction: column;
}
label, input {
margin-bottom: 10px;
}
button {
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h2>Fee Payment Form</h2>
<form id="paymentForm">
<label for="name">Student Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="amount">Amount:</label>
<input type="number" id="amount" name="amount" required>
<label for="cvv">CVV:</label>
<input type="text" id="cvv" name="cvv" required>
<script>
const form = document.getElementById('paymentForm');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = {
name: form.name.value,
email: form.email.value,
amount: form.amount.value,
cardNumber: form.cardNumber.value,
expiryDate: form.expiryDate.value,
cvv: form.cvv.value,
};
try {
const response = await fetch('/pay', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(formData),
});
console.error('Error:', error);
alert('Payment failed. Please try again.');
}
});
</script>
</body>
</html>
Step 3: Set Up the Back-end with Express
Create a server.js file with the following content:
const express = require('express');
const bodyParser = require('body-parser');
const { MongoClient } = require('mongodb');
// Connection URL
const url = 'mongodb://localhost:27017'; // Replace with your MongoDB connection string
const client = new MongoClient(url);
const dbName = 'feePaymentDB';
app.use(bodyParser.json());
app.use(express.static('public'));
// Connect to MongoDB
async function connectToDB() {
await client.connect();
console.log('Connected to MongoDB');
}
connectToDB().catch(console.error);
try {
const db = client.db(dbName);
const collection = db.collection('payments');
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
Step 4: Run the Application
1. Create a directory named public and move the index.html file into it.
mkdir public
mv index.html public/
2. Start the Server:
node server.js
3. Access the Form: Open your web browser and navigate to http://localhost:3000. You should
see the online fee payment form.
Explanation
Front-end: The form collects payment details, and JavaScript handles the submission to
the server.
Back-end: Express handles incoming form submissions, and MongoDB is used to store
payment details.
Database: The payments collection within the feePaymentDB database stores each
payment's data.