Wednesday, March 10, 2021

Script Vs Program Vs Software Vs Applications

 SCRIPT


A computer script is a list of commands that are executed by a certain program or scripting engine. 

For example all batch files ( .bat) files in Windows is a script written in DOS commands. 

Scripts may be used to automate processes on a local computer (batch files)  or to generate Web pages on the Web (web server). 

For example, DOS scripts (batch files) and VB Scripts may be used to run processes on Windows machines, while AppleScript scripts can automate tasks on Macintosh computers. 

ASPJSP, and PHP scripts are often run on Web servers to generate dynamic Web page content.

Script files are usually just text documents that contain instructions written in a certain scripting language. 

This means most scripts can be opened and edited using a basic text editor. However, when opened by the appropriate scripting engine, the commands within the script are executed. 

VB (Visual Basic) scripts, for example, will run when double-clicked, using Windows' built-in VB scripting support. 

Since VB scripts can access and modify local files, you should never run a VB script that you receive as an unknown e-mail attachment.

WEB SERVER

A web server is a computer that runs websites.

It's a computer program that distributes web pages as they are requisitioned.

The basic objective of the web server is to store, process and deliver web pages to the users.

This intercommunication is done using Hypertext Transfer Protocol (HTTP). 

These web pages are mostly static content that includes HTML documents, images, style sheets, test etc. 

Apart from HTTP, a web server also supports SMTP (Simple Mail transfer Protocol) and FTP (File Transfer Protocol) protocol for emailing and for file transfer and storage.

The main job of a web server is to display the website content. 

If a web server is not exposed to the public and is used internally, then it is called Intranet Server. 

When anyone requests for a website by adding the URL or web address on a web browser’s (like Chrome or Firefox) address bar (like www.economictimes.com), the browser sends a request to the Internet for viewing the corresponding web page for that address. 

A Domain Name Server (DNS) converts this URL to an IP Address (For example 192.168.216.345), which in turn points to a Web Server.


PROGRAM

Program is a common computer term that can be used as both a noun and a verb. 

A program (noun) is executable software that runs on a computer. 

It is similar to a script, but is often much larger in size and does not require a scripting engine to run. 

Instead, a program consists of compiled code that can run directly from the computer's operating system.

These programs are often called applications, which can be used synonymously with "software programs." 

On Windows, programs typically have an .EXE file extension, while Macintosh programs have an .APP extension.


When "program" is used as verb, it means to create a software program. 

For example, programmers create programs by writing code that instructs the computer what to do. 

The functions and commands written by the programmer are collectively referred to as source code

When the code is finished, the source code file or files are compiled into an executable program.

When programmers create software programs, they first write the program in source code, which is written in a specific programming language, such as C or Java

These source code files are saved in a text-based, human-readable format, which can be opened and edited by programmers. 

However, the source code cannot be run directly by the computer. In order for the code to be recognized by the computer's CPU, it must be converted from source code (a high-level language) into machine code (a low-level language). This process is referred to as "compiling" the code.

SOFTWARE

Computer software is a general term that describes computer programs.

Related terms such as software programs, applications, scripts, and instruction sets all fall under the category of computer software. Therefore, installing new programs or applications on your computer is synonymous with installing new software on your computer.

Source: Techterms

Monday, March 8, 2021

JSP program showing account details by taking account number as input.

 //File 'Bank.jsp' inside the 'Web pages' folder to display account details

<%-- 

    Document   : Bankjsp

    Created on : 19 Mar, 2020, 12:04:04 PM

    Author     : ashu

--%>

<%@ page import="java.io.*,java.util.*,java.sql.*"%>

<%@ page import="javax.servlet.http.*,javax.servlet.*" %>

<%@ page import="java.math.*"%>

<%@ page import="java.sql.Connection"%>

<%@ page import="java.sql.DriverManager"%>

<%@ page import="java.sql.ResultSet"%>

<%@ page import="java.sql.SQLException"%>

<%@ page import="java.sql.Statement"%>

<%@ page language="java"%>

<%@ page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

    <head>

        <title>Real Bank JSP Page</title>

        <script>

            function printDiv(divName) {

                var printContents = document.getElementById(divName).innerHTML;

                var originalContents = document.body.innerHTML;


                 document.body.innerHTML = printContents;


                 window.print();


                document.body.innerHTML = originalContents;

        }

        </script>

    </head>

    <body>

    <div id="printableArea">                //For the 'print' button 

    <center>

        <h1>Welcome to Real Bank!</h1>

        <h3>Customers with balance greater than Rs.5000/- in SB a/c </h3>

        

        <%

            try {

            String connectionURL = "jdbc:mysql://localhost/bank";

            Class.forName("com.mysql.jdbc.Driver").newInstance(); 

            Connection con = DriverManager.getConnection(connectionURL, "root", "ashutosh");

            if(con.isClosed()){

                 out.println("Successfully connected to " + "MySQL server using TCP/IP...");

            }

            Statement stmt = con.createStatement();

            ResultSet rs = stmt.executeQuery("select customerName, customerAddress, accountNum from customers where accountType='SB' and balance >= 5000.00;");

            %>

            <table border=1>

            <tr><th>Name</th><th>Address</th><th>Account Number</th></tr>

            <%

            while(rs.next()){

            %>

            <tr>

            <td><%=rs.getString(1)%></td>

            <td><%=rs.getString(2)%></td>

            <td><%=rs.getInt(3)%></td>

            </tr>

        <%   

        }

        rs.close();

        stmt.close();

        con.close();

        }catch(Exception ex){

            out.println("Unable to connect to database"+ex);

        }  

        %>

        </table>

        <br><br>   

        <%

            out.println("<input type= 'button' onclick=printDiv('printableArea') value='Print'>");

        %>

        <br><br>

        <%

            

            out.println("<input type= 'button' onclick=location.href='index.html' value='back'>");

        %>

        

    </center>

    </div>

    </body>

</html>

--------------------------------------------------------------------------------------------------------
//The 'Accountjsp.jsp' file to fetch account details for a given account number

<%-- 
    Document   : Accountjsp
    Created on : 9 Mar, 2021, 8:31:38 AM
    Author     : ashu
--%>

<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ page import="java.math.*"%>
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.DriverManager"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.sql.SQLException"%>
<%@ page import="java.sql.Statement"%>
<%@ page language="java"%>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Account Details</title>
        <script>
            function printDiv(divName) {
                var printContents = document.getElementById(divName).innerHTML;
                var originalContents = document.body.innerHTML;

                 document.body.innerHTML = printContents;

                 window.print();

                document.body.innerHTML = originalContents;
        }
        
        
        </script>
    </head>
    <body>
    <div id="printableArea">
    <center>
        <h1>Welcome to Real Bank!</h1>
 
        
        <%
            try {
            String connectionURL = "jdbc:mysql://localhost/bank";
            Class.forName("com.mysql.jdbc.Driver").newInstance(); 
            Connection con = DriverManager.getConnection(connectionURL, "root", "ashutosh");
            if(con.isClosed()){
                 out.println("Successfully connected to " + "MySQL server using TCP/IP...");
            }
            Statement stmt = con.createStatement();
            
            String account_number = request.getParameter("acNum");
            //out.println(account_number);
            ResultSet rs = stmt.executeQuery("select customerName, customerAddress, accountNum, balance, accountType from customers where accountNum = " + account_number + ";");
            %>
            <table border=1>
            <tr><th>Name</th><th>Address</th><th>Account Number</th><th>Balance</th><th>Account Type</th></tr>
            <%
            while(rs.next()){
            %>
            <tr>
            <td><%=rs.getString(1)%></td>
            <td><%=rs.getString(2)%></td>
            <td><%=rs.getInt(3)%></td>
            <td><%=rs.getString(4)%></td>
            <td><%=rs.getString(5)%></td>
            </tr>
        <%   
        }
        rs.close();
        stmt.close();
        con.close();
        }catch(Exception ex){
            out.println("Unable to connect to database"+ex);
        }  
        %>
        </table>
        <br><br>   
        <%
            out.println("<input type= 'button' onclick=printDiv('printableArea') value='Print'>");
        %>
        <br><br>
        <%
            
            out.println("<input type= 'button' onclick=location.href='index.html' value='back'>");
        %>
        
    </center>
    </div>
    </body>
</html>


---------------------------------------------------------------------------------------------------------

//Corresponding HTML page 'index.html'
<!DOCTYPE html>
<!--

To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>Real Bank</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
    <center><h1>Welcome to Real Bank!</h1>
        <h2>You can bank with us for best returns and services</h2>
    <div>Details of customers having greater than equal to Rs.5000/- in savings account</div>
    <br><br>
    <input type= "button" onClick="location.href='Bank.jsp'" value="Click to view details">
    <br><br>
    <div>Details of customer having savings account number: <input type= "text" id = "acNum" name = "acNum" maxlength = "10" size = "10"></div>
    <br><br>
    
<!-- Excellent way to send textbox value from HTML file to a JSP file -->
    <input type= "button" onClick='location.href = "Accountjsp.jsp?acNum="  + document.getElementById("acNum").value;'  value ="Account details">
    
    </center>
        
    </body>
</html>

-------------------------------------------------------------------------------------------------------------------
//Project directory structure




----------------------------------------------------------------------------------------------------------------------
//Output

//index page at url = http://localhost:8080/jspJDBC/
//Syntax for url of index file = http://localhost:<port_number>/<project_name>/





----------------------------------------------------------------------------------------------------------------

// The 'Bank.jsp' page opens on clicking the button 'Click to View Details' at the index (Home) page




-----------------------------------------------------------------------------------------------------------------------

//Result of clicking the 'Print' button


The actual pronted PDF file


----------------------------------------------------------------------------------------------------------------
Output for 'Account Details' button





Output of print button of this page





Java Servlet simple example

 //Servlet file name 'RandomGreetings.java'.

//Run on NetBeans IDE 8.2

/*

 * A Servlet that returns a randomly chosen greeting from a list of five

 * different greetings. The greetings must be stored as constant strings

 * in the program.

 */


import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;


import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

//

import java.util.Random;

//

@WebServlet(urlPatterns = {"/RandomGreetings"})

//

public class RandomGreetings extends HttpServlet 

{   

    //Five greetings saved as constan strings

    public static final String STR1 = "Good morning";

    public static final String STR2 = "Good night";

    public static final String STR3 = "Good afternoon";

    public static final String STR4 = "Good day";

    public static final String STR5 = "Welcome";

    //

    String[] arr = {STR1,STR2,STR3,STR4,STR5};

    //

        Random ran = new Random();

    //

    protected void doGet(HttpServletRequest request, HttpServletResponse response)

            throws ServletException, IOException 

    {

        

        //

        int random = ran.nextInt(5);

        //

        String g = arr[random];

        response.setContentType("text/html");

        PrintWriter out = response.getWriter(); 

        out.println("<!DOCTYPE html>");

        out.println("<html>");

        out.println("<head>");

        out.println("<title>Random Greetings</title>");            

        out.println("</head>");

        out.println("<body>");

        out.println(g);

        out.println("</body>");

        out.println("</html>");

    }

}

-----------------------------------------------------------------------------------------------

//Corresponding HTML index file (index.html)

<!DOCTYPE html>
<!--
A simple markup document to test the Servlet
-->
<html>
    <head>
        <title>Random Greetings</title>
        <meta charset="UTF-8">
    </head>
    <body>
        <div>
            <form action="RandomGreetings" method="get">
                Press the button to test the Servlet
                <input type="submit" value="Test Servlet"/>
            </form>
        </div>
    </body>
</html>
 --------------------------------------------------------------------------------------------------

//Project directory structure at location: C:\Users\ashu\Documents\NetBeansProjects\ServletE1


-------------------------------------------------------------------------------------------------------------------------

Output:

//On running the servlet, the IDE opens the 'index.html'  page at url = http://localhost:8080/ServletE1/) 
//Syntax of index page url = http://localhost:<port_numer>/<project_name>/


//Button click executes the servlet at url = http://localhost:8080/ServletE1/RandomGreetings?
//NOTE: You need to run each servlet file one by one in the project (if it has multiple servlet files/java files in the 'Source Packages' folder)

//Syntax for the servlet url = http://localhost:<port_number>/<project_number>/<servlet_file_name_without_.java_extension>?




----------------------------------------------------------------------------------------------------------------------


Sunday, March 7, 2021

JSP program to display, add and modify employee details

 //JSP file to display employee details

<%-- 

    Document   : employeeDetails

    Created on : 21 Mar, 2020, 6:02:56 AM

    Author     : ashu

--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ page import="java.io.*,java.util.*,java.sql.*"%>

<%@ page import="javax.servlet.http.*,javax.servlet.*" %>

<%@ page import="java.math.*"%>

<%@ page import="java.sql.Connection"%>

<%@ page import="java.sql.DriverManager"%>

<%@ page import="java.sql.ResultSet"%>

<%@ page import="java.sql.SQLException"%>

<%@ page import="java.sql.Statement"%>

<%@ page language="java"%>

<!DOCTYPE html>

<html>

    <head>

        <title>Employees</title>

    </head>

    <body>

    <center>

        <h1>Welcome to JavaTech!</h1>

        <h3>Following is the details of our employees</h3>

        <a href="index.html">Home</a>&nbsp;&nbsp;

        <a href="addEmployee.html">Add Employee</a>&nbsp;&nbsp;

        <a href="modifyDetails.html">Modify Details</a>

        <br><br>

        <%

            try {

            String connectionURL = "jdbc:mysql://localhost/employees";

            Class.forName("com.mysql.jdbc.Driver").newInstance(); 

            Connection con = DriverManager.getConnection(connectionURL, "root", "ashutosh");

            Statement stmt = con.createStatement();

            ResultSet rs = stmt.executeQuery("select * from employee;");

        %>

        <br>   

        <table border=1>

                <tr><th>EmpID</th><th>PhoneNo</th><th>Name</th><th>Address</th><th>Department</th><th>Salary(Rs.)</th></tr>

        <%

            while(rs.next()){

        %>

            <tr>

            <td><%=rs.getInt(1)%></td>

            <td><%=rs.getInt(2)%></td>

            <td><%=rs.getString(3)%></td>

            <td><%=rs.getString(4)%></td>

            <td><%=rs.getString(5)%></td>

            <td><%=rs.getFloat(6)%></td>

            </tr>

        <%   

        }

        rs.close();

        stmt.close();

        con.close();

        }catch(Exception ex){

            out.println("Unable to connect to database"+ex);

        }   

        %>

        

    </center>

    </body>

</html>

---------------------------------------------------------------------------------------------------------------
//Corresponding HTML file

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>JavaTech</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
    <center><h1>Welcome to JavaTech</h1>
        <hr>
        <h2>Manage all employee activities from here</h2>
        <hr>
        <div>
            <a href="employeeDetails.jsp">Get details of each employees</a>&nbsp;&nbsp;
            <a href="addEmployee.html">Add a new employee</a>&nbsp;&nbsp;
            <a href="modifyDetails.html">Modify existing employee details</a>
        </div>
    </center>
    </body>
</html>
----------------------------------------------------------------------------------------------------------------

//JSP file to add employee details

<%-- 
    Document   : addEmployee
    Created on : 21 Mar, 2020, 6:47:29 AM
    Author     : ashu
--%>

<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ page import="java.math.*"%>
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.DriverManager"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.sql.SQLException"%>
<%@ page import="java.sql.Statement"%>
<%@ page language="java"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Employees</title>
    </head>
    <body>
    <center>
        <h1>Welcome to JavaTech!</h1>
        <a href="index.html">Home</a>&nbsp;&nbsp;
        <a href="modifyDetails.html">Modify Details</a>
        <h3>You can add a new employee</h3>
        
        <%
            try {
            String connectionURL = "jdbc:mysql://localhost/employees";
            Class.forName("com.mysql.jdbc.Driver").newInstance(); 
            Connection con = DriverManager.getConnection(connectionURL, "root", "ashutosh");
            Statement stmt = con.createStatement();
            String ph=request.getParameter("phNum");
            String name=request.getParameter("name");
            String address=request.getParameter("address");
            String dept=request.getParameter("dept");
            String salary=request.getParameter("salary");
            long phNumInt = Long.parseLong(ph);
            float salaryFt = Float.parseFloat(salary);
            stmt.executeUpdate("INSERT INTO employee(phNum,empName,empAddress,empDept,salary) values("+phNumInt+",'"+name+"','"+address+"','"+dept+"',"+salaryFt+");");
            out.println("New employee added sucessfully!");  
            out.println("<br><a href=\"employeeDetails.jsp\">Verify the change</a>");
        stmt.close();
        con.close();
        }catch(Exception ex){
            out.println("Unable to connect to database"+ex);
        }   
       %>
    </center>
    </body>
</html>
-------------------------------------------------------------------------------------------------------------

//Corresponding HTML file

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>Add Employee</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script>
        function validateForm()
        {
            var name = document.myform.name.value;
            var phNum = document.myform.phNum.value;
            var address = document.myform.address.value;
            var dept = document.myform.dept.value;
            var salary = document.myform.salary.value;
            if(name===""||name===null)
            {
                alert("User Name should not be left blank");
                document.myform.name.focus();
                return false;
            }
            if(phNum===""||phNum===null)
            {
                alert("Phone number should not be left blank");
                document.myform.phNum.focus();
                return false;
            }
            if(address===""||address===null)
            {
                alert("address should not be left blank");
                document.myform.address.focus();
                return false;
            }
            if(dept===""||dept===null)
            {
                alert("Department should be not left blank");
                document.myform.dept.focus();
                return false;
            }
            if(salary===""||salary===null)
            {
                alert("Salary should be not left blank");
                document.myfrm.salary.focus();
                return false;
            }
            //phone number must be a number
            if(isNaN(phNum)){  
                alert("Phone number can have Numeric value only");  
                return false;  
            }
            //salary must be a number
            if(isNaN(salary)){  
                alert("Salary can have Numeric value only");  
                return false;  
            }
            if(phNum.length<9){  
                alert("Phone number must be at least 9 digits long.");  
                return false;  
            }  
        }
        </script>
    </head>
    <body>
    <center><h1>Add New Employee</h1>
        <a href="index.html">Home</a>&nbsp;&nbsp;<a href="employeeDetails.jsp">Employee Details</a>&nbsp;&nbsp;<a href="modifyDetails.html">Modify existing employee details</a><br><br>
        <div>
        <form name="myform" method="post" action="addEmployee.jsp" onsubmit="return validateForm()" >  
            <table>
                <tr><td>Name:</td><td><input type="text" name="name"></td></tr> 
                <tr><td>Phone Number:</td><td><input type="text" name="phNum"></td><tr/> 
                <tr><td>Address:</td><td><input type="text" name="address"></td><tr/>
                <tr><td>Department:</td><td><input type="text" name="dept"></td><tr/>
                <tr><td>Salary:</td><td><input type="text" name="salary"></td><tr/>
                <tr><td><input type="submit" value="add"></td></tr>  
            </table>
</form>  
        </div>
    </center>
    </body>
</html>
-----------------------------------------------------------------------------------------------------------

//JSP file to modify employee details

<%-- 
    Document   : modifyDetails
    Created on : 21 Mar, 2020, 8:25:41 AM
    Author     : ashu
--%>

<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ page import="java.math.*"%>
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.DriverManager"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.sql.SQLException"%>
<%@ page import="java.sql.Statement"%>
<%@ page language="java"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Mofify Employee Details</title>
    </head>
    <body>
    <center>
        <h1>Welcome to JavaTech!</h1>
        <a href="index.html">Home</a>&nbsp;&nbsp;
        <a href="addEmployee.html">Add Employee</a>
        <h3>You can modify employee details here</h3>
        
        <%
            try {
            String connectionURL = "jdbc:mysql://localhost/employees";
            Class.forName("com.mysql.jdbc.Driver").newInstance(); 
            Connection con = DriverManager.getConnection(connectionURL, "root", "ashutosh");
            Statement stmt = con.createStatement();
            String empID="";
            String ph="";
            String name="";
            String address="";
            String dept="";
            String salary="";
            long phNumInt=0;
            float salaryFt=0;
            
            empID=request.getParameter("empid");
            ph=request.getParameter("phNum");
            name=request.getParameter("name");
            address=request.getParameter("address");
            dept=request.getParameter("dept");
            salary=request.getParameter("salary");
            int empIDInt = Integer.parseInt(empID);
            
            if(ph!=""){
                phNumInt = Long.parseLong(ph);}
            if(salary!=""){
                salaryFt = Float.parseFloat(salary);}
            if(ph!=""){
            stmt.executeUpdate("UPDATE employee SET phNum = '"+phNumInt+"'WHERE empID = "+empIDInt+";");
            }
            if(name!=""){
            stmt.executeUpdate("UPDATE employee SET empName = '"+name+"'WHERE empID = "+empIDInt+";");
            }
            if(address!=""){
            stmt.executeUpdate("UPDATE employee SET empAddress = '"+address+"'WHERE empID = "+empIDInt+";");
            }
            if(dept!=""){
            stmt.executeUpdate("UPDATE employee SET empDept = '"+dept+"'WHERE empID = "+empIDInt+";");
            }
            if(salary!=""){
            stmt.executeUpdate("UPDATE employee SET salary = '"+salaryFt+"'WHERE empID = "+empIDInt+";");
            }
            out.println("Employee details modified sucessfully!");
            out.println("<br><a href=\"employeeDetails.jsp\">Verify the change</a>");
           
            stmt.close();
            con.close();
        }catch(Exception ex){
            out.println("Unable to connect to database"+ex);
        }   
       %>
       
    </center>
    </body>
</html>
-----------------------------------------------------------------------------------------------------------

// Coresponding HTML file

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>Modify Employee Details</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script>
            
        function validateForm()
        {   
            var empID = "";
            var name = "";
            var phNum = "";
            var address = "";
            var dept = "";
            var salary = "";
            
            empID = document.myform.empid.value;
            name = document.myform.name.value;
            phNum = document.myform.phNum.value;
            address = document.myform.address.value;
            dept = document.myform.dept.value;
            salary = document.myform.salary.value;
            
            if(empID===""||empID===null)
            {
                alert("Employee ID should not be left blank");
//The following two lines are must for every validation alert, else it will not wait for 
//the blank text box getting filled/corrected.
                document.myform.empid.focus();
                return false;
            }
            
            var checkboxes = document.querySelectorAll('input[type="checkbox"]');
            var checkedOne = Array.prototype.slice.call(checkboxes).some(x => x.checked);
            
                       if(!checkedOne){
                 alert("'At least one checkbox must be selected.'");
                 return false;
             }
            
             
            if((document.getElementById("cbname").checked) && name==="")
            {
                alert("Employee Name should not be left blank");
                document.myform.name.focus();
                return false;
            }
            if((document.getElementById('cbphNum').checked) && phNum==="" )
            {
                alert("Employee phone number should not be left blank");
                document.myform.phNum.focus();
                return false;
            }
            if((document.getElementById('cbaddress').checked) && address==="")
            {
                alert("Employee address should not be left blank");
                document.myform.address.focus();
                return false;
            }
            if((document.getElementById('cbdept').checked) && dept==="")
            {
                alert("Employee Department should be not left blank");
                document.myform.dept.focus();
                return false;
            }
            if((document.getElementById('cbsalary').checked) && salary==="")
            {
                alert("Employee Salary should be not left blank");
                document.myform.salary.focus();
                return false;
            }
            //phone number must be a number
            if(isNaN(phNum)){  
                alert("Phone number can have Numeric value only");  
                return false;  
            }
            //salary must be a number
            if(isNaN(salary)){  
                alert("Salary can have Numeric value only");  
                return false;  
            }
            if((document.getElementById('cbphNum').checked) && phNum.length<9){  
                alert("Phone number must be at least 9 digits long.");  
                return false;  
            }
            
        }
        
        </script>
    </head>
    <body>
    <center><h1>Modify Employee Details</h1>
        <a href="index.html">Home</a>&nbsp;&nbsp;
        <a href="addEmployee.html">Add Employee</a>&nbsp;&nbsp;
        <a href="employeeDetails.jsp">Employee Details</a>
        <h3>Enter the employee ID of the employee whose details has to be modified and</h3>
        <h3>Select at least one field that you want to modify:</h3>
        <div>
        <form id="cform" name="myform" method="post" action="modifyDetails.jsp" onsubmit="return validateForm()" >  
            <table>
                <tr><td>Employee ID:</td><td><input type="text" name="empid"></td></tr>
                <tr><td><input type="checkbox" id="cbname">Name:</<td><td><input type="text" name="name"></td></tr> 
                <tr><td><input type="checkbox" id="cbphNum">Phone Number:</td><td><input type="text" name="phNum"></td><tr/> 
                <tr><td><input type="checkbox" id="cbaddress">Address:</td><td><input type="text" name="address"></td><tr/>
                <tr><td><input type="checkbox" id="cbdept">Department:</td><td><input type="text" name="dept"></td><tr/>
                <tr><td><input type="checkbox" id="cbsalary">Salary:</td><td><input type="text" name="salary"></td><tr/>
                <tr><td><input type="submit" value="modify"></td></tr>  
            </table>
</form>  
           
        </div>
    </center>
    </body>
</html>

Basic Flask web app

 from flask import Flask app = Flask(__name__) #In Flask, URL rules can be added using either the @app.route() decorator or the app.add_url_...