Tuesday, 12 March 2024

Running Simple JSP file from Apache Tomcat Webserver

 Running Simple JSP file from Apache Tomcat Webserver


1. Create file with name user.html inside D:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\ROOT (change drive name if needed)

<!DOCTYPE html>

<html>

<head>

<title>JSP Demo</title>

</head>

<body>

<form action="welcome.jsp" method="get" > 

<p>Enter a Name:<input type="text" name="uname"/></p><br/> 

<input type="submit" value="Submit">

</form>

</body>

</html>


2. Create a file with name welcome.jsp inside D:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\ROOT (change drive name if needed)

<%

String user=request.getParameter("uname");

        out.println("Hello "+user);

%>


3. Open browser and type the url localhost:8080/user.html 


Wednesday, 21 April 2021

AJAX Web Application for Reading Data from XML

 cdcatalog.xml

<?xml version="1.0" encoding="UTF-8"?>
<CATALOG>
  <CD>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1985</YEAR>
  </CD>
  <CD>
    <TITLE>Hide your heart</TITLE>
    <ARTIST>Bonnie Tyler</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>CBS Records</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1988</YEAR>
  </CD>
  <CD>
    <TITLE>Greatest Hits</TITLE>
    <ARTIST>Dolly Parton</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>RCA</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1982</YEAR>
  </CD>
</CATALOG>

readxml.html

<!DOCTYPE html>
<html>
<head>
<script>
function loadDoc() 
{
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() 
{
if (this.readyState == 4 && this.status == 200) 
{
var xmlDoc = xhttp.responseXML;
var table="<table border='1'><tr><th>Title</th><th>Price</th><th>Year</th></tr>";
var x = xmlDoc.getElementsByTagName("CD");
for (i = 0; i <x.lenght; i++) 
{
table += "<tr><td>" +
x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("PRICE")[0].childNodes[0].nodeValue +
"</td><td>"+
x[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue +
"</td></tr>"
}
table+="</table>";
document.getElementById("demo").innerHTML = table;
}
};
xhttp.open("GET", "cdcatalog.xml", true);
xhttp.send();
}
</script>
</head>
<body onload="loadDoc()">
<h1>Reading XML Data</h1>
<div id="demo"></div>
</body>
</html>

AJAX Web Applications with Database Access

 Cricket Score Display using AJAX

score.html

<!DOCTYPE html>
<html>
<head>
<script>
function viewScore()
{
request=new XMLHttpRequest();
request.open("GET","dbaccess.php",true);
request.send();
try
{
request.onreadystatechange=function()
{
if(request.readyState==4 & request.status=200)
{
document.getElementById('score').innerHTML=request.responseText;
}
};

}
catch(e)
{
alert("Unable to connect to server");
}
}
setInterval(viewScore,1000);
</script>
</head>
<body>
<h1>Retrive data from database using AJAX</h1>
<div id="score"><h2></h2></div>
</body>
</html>



dbaccess.php

<?php
// Create connection
$conn = new mysqli("localhost","abcd","1234", "test");

// Check connection
if ($conn->connect_error) 
{
    die("Connection failed:".$conn->connect_error);
}
$sql = "SELECT * FROM IPL";
$result = $conn->query($sql);
if ($result->num_rows > 0) 
{
    // output data of each row
    while($row = $result->fetch_assoc()) 
    {
        echo "Score:".$row["score"]."/".$row["wicket"]." Overs:".$row["over"];
    }
else 
{
    echo "0 results";
$conn->close();
?>

Friday, 26 February 2021

Storing Data into a Database

STEPS FOR STORING DATA INTO DATABASE

Step:1 Create table (Eg. student) in database(eg:test)

Step:2 Create client side webpage(insert.html) for getting data from users and store into D:\xampp\htdocs folder.

<!DOCTYPE html>
<html>
<head>
<title>Store Data into Database</title>
<style>
h1,div
{
text-align:center;
}
#sds-header
{
color:white;
height:50px;
width:100%;
background-color:green;
font-size:25px;
padding-top:15px;
}
#sds-form
{
color:blue;
height:550px;
width:100%;
background-color:yellow;
font-size:25px;
padding-top:25px;
}
</style>
</head>
<body>
<div id="sds-header">
Student Database System
</div>
<div id="sds-form">
<form name="myform" action="insertdb.php" method="get">
<input type="text" name="uroll" placeholder="Roll Number"><br><br>
<input type="text" name="uname" placeholder="Name"><br><br>
<input type="text" name="uage" placeholder="Age"><br><br>
<input type="text" name="udept" placeholder="Department"><br><br>
<input type="submit" value="Insert">
</form>
</div>
</body>
</html>

Step:3 Create an another webpage(insertdb.php) in D:\xampp\htdocs folder using PHP for collecting data from previous page and storing those data into a table(eg. student) present in the database(eg. test).

<?php
$rollno=$_GET['uroll'];
$name=$_GET['uname'];
$age=$_GET['uage'];
$dept=$_GET['udept'];

// Create connection
$conn = new mysqli("localhost", "siva", "123", "test");
// Check connection
if ($conn->connect_error) 
{
die("Connection failed:" . $conn->connect_error);
}

$sql = "INSERT INTO STUDENT VALUES('$rollno','$name','$age','$dept')";

if(mysqli_query($conn, $sql))
{
echo "Records inserted successfully.";
else
{
echo "ERROR: Could not execute $sql. " . mysqli_error($conn);
}
$conn->close();
?>

Step:4 Run the first page http://localhost/insert.html




Step:5 Enter details in the form and click insert

Step:6 Now you  will see the following screen after successful insertion.

THANK YOU



Thursday, 25 February 2021

USERNAME PASSWORD VERIFICATION USING PHP AND MYSQL

LOGIN FORM VERIFICATION USING DATABASE

 Step:1 Create login page(login.html) in  \xampp\htdocs folderusing the following HTML code

<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
<style>
h1,div
{
text-align:center;
}
</style>
</head>
<body>
<h1>Login</h1>
<div>
<form name="myform" action="dbselect.php" method="post">
User Name:<input type="text" name="uname"><br><br>
Password:<input type="password" name="pass"><br><br>
<input type="submit" value="Login">
</form>
</div>
</body>
</html>

Step:2 Create a following PHP file(dbselect.php) to verify username and password using database data

<?php

$uname=$_POST['uname'];
$pass=$_POST['pass'];
$status=0;
// Create connection
$conn = new mysqli("localhost", "siva", "123", "test");
// Check connection
if ($conn->connect_error) 
{
die("Connection failed:" . $conn->connect_error);
}
$sql = "SELECT * FROM login";
$result = $conn->query($sql);
if ($result->num_rows > 0) 
{
  while($row = $result->fetch_assoc()) 
  {
if(!strcmp($row["username"],$uname)&&!strcmp($row["password"],$pass))
{
$status=1;
break;
}
  }

else 
{
  echo "No Records Found";
}
if($status==1)
{
// 301 Moved Permanently
header("Location: http://localhost/welcome.php", true, 301);
exit();
}
//echo "Login Succes";
else
echo "Login Failed";
$conn->close();
?>

Step:3 Save this file with name dbselect.php or any other name with .php extension in the same folder (\xampp\htdocs\). Ensure this filename and filename given action attribute of the login form is same.

    <form name="myform" action="dbselect.php" method="post">

Step:4 Run login.html file as follows from your web browser

http://localhost/login.html


Step:5 Type username and password available in the database. The login records available in the database as follows

Step:6 Now you will see the following page



THANK YOU




Wednesday, 24 February 2021

Creating Table in XAMPP-PHP-MySQL Database

Create a table in PHP-MySQL database

Note: Install XAMPP PHP Web Server in your machine

Step-1: Type http://localhost/phpmyadmin/ in address bar of your browser

Step:2: From the left side bar, click any one database(Eg: test)


Step:3 Below the create table, type table name(eg:user) and specify number of columns(Eg.2), then click Go button.


Step:4 Enter table column names, type and length as follows, then click save. 


Step:5 Now you will see the following screen.


Step:6 Click the SQL Tab and then INSERT button and run the insert query as follows for inserting username and password for two users as follows

INSERT INTO `users`(`username`, `password`) VALUES ("abc","123456")


Step:7 Now you will see the following screen after successful insertion
.

Step:8 Now click table name(Eg:users) from left side, you will see the following screen will show all records present in the table.


THANK YOU

Tuesday, 23 February 2021

Installing PHP Server - XAMPP in Windows

Installing XAMPP in Windows OS

  • Go to this link "https://www.apachefriends.org/download.html"
  • Choose latest xampp version for windows
  • After clicking exe file will be downloaded in your machine
  • Right click on the downloaded file and click run as administrator
  • Click Next
  • Again click Next
  • Now, Change folder from "C:\" drive to "D:\" drive or any other
  • Click Next
  • Click Next
  • Click Next
  • Click Next, now installation will start
  • After installation, click XAMPP Control Panel from windows menu and Start the Apache, MySQL and Tomcat Module


  • Now, type "localhost" in the browser address bar and you will see the following screen:
  • Now create a simple php file(example: test.php) in the notepad and save the file in "D:\xampp\htdocs folder"
  • Now in the web browser address bar type "localhost/test.php" and see output as follows:
test.php

<?php
echo "Welcome to php";
?>




Thank you