Saturday, March 13, 2021

Simple Servlet program to query books details and update a book's availability status by taking book ID as input

 //The HTML index page

<!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></title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

    </head>

    <body>

        

    <center>

        <h1>Welcome to the IGNOU RC Varanasi website</h1>

        <h3>Here you can have all information about counselling classes and library books</h3>

        

        <!-- books.java is the Servlet file which should get executed/invoked once below link is clicked, -->

        

        <div>For books availability in the library <a href="books">click here</a></div>

        

        <!-- modifyBooks.java is the Servlet file which should get executed/invoked once below link is clicked, -->

        <br><br>

        <div>For modifying a book's availability status in the library

            

            <form method="POST" action="modifyBooks">

                <br><br>

            enter book id <input type = "text" id ="bookId" name ="bookId"> 

            <br><br>

            enter new availability status (Yes/No) <input type = "text" id ="status"  name ="status">

            <br><br>

                <button type="submit"> Update </button>

            </form>

        </div>

        

        

    </center>

    </body>

</html>

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

//The 'books.java' servlet

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Library;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
 *
 * @author ashu
 */
public class books extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
    try{
        out.println("<html>");
        out.println("<head><title>Servlet JDBC</title></head>");
        out.println("<body>");
        // connecting to database
        Class.forName("com.mysql.jdbc.Driver");
        Connection con =DriverManager.getConnection ("jdbc:mysql://localhost/dbmsbooks","root","ashutosh");
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM dbbooks");
        // displaying records
        out.println("<center>");
        out.println("<h1>IGNOU RC Varanasi website</h1>");
        out.println("<h2>"+"Following is the details of the books available in library related to DBMS: "+"</h2>");
        out.println("<table border=1>");
        out.println("<tr><th>BookID</th><th>Title</th><th>Authors</th><th>Publication</th><th>Availability</th></tr>");
        while(rs.next()){
            out.println("<tr>");
            out.println("<td>"+rs.getInt(1)+"</td>"+
                        "<td>"+rs.getString(2)+"</td>"+
                        "<td>"+rs.getString(3)+"</td>"+
                        "<td>"+rs.getString(4)+"</td>"+
                        "<td>"+rs.getString(5)+"</td>");
            out.println("</tr>");
        }
        out.println("</center></body></html>");  
  } catch (SQLException e) {
 throw new ServletException("Servlet Could not display records.", e);
  } catch (ClassNotFoundException e) {
  throw new ServletException("JDBC Driver not found.", e);
  } 
  out.close();
  }
        


    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
-----------------------------------------------------------------------------------------------------

//The 'modifyBooks.java' servlet

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Library;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
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;

/**
 *
 * @author ashu
 */
@WebServlet(name = "modifyBooks", urlPatterns = {"/modifyBooks"})

public class modifyBooks extends HttpServlet { 

    /**
     *
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)

            throws ServletException, IOException 

    {   
        response.setContentType("text/html;charset=UTF-8");
        
    try(PrintWriter out = response.getWriter()) {
        try{
            out.println("<html>");
            out.println("<head><title>Servlet JDBC</title></head>");
            out.println("<body>");
            // connecting to database
            Class.forName("com.mysql.jdbc.Driver");
            Connection con =DriverManager.getConnection ("jdbc:mysql://localhost/dbmsbooks","root","ashutosh");
            Statement stmt = con.createStatement();
            
            String bookId = request.getParameter("bookId");
            String status = request.getParameter("status");
            //out.println(bookId);
            //out.println(status);
            
            stmt.executeUpdate("UPDATE dbbooks SET available = '" + status + " 'WHERE bookID = "+bookId+";");
            
            out.println("Book status updated successfuly!");
            out.println("</body></html>");
        } catch (SQLException e) {
            throw new ServletException("Servlet Could not display records.", e);
        } catch (ClassNotFoundException e) {
            throw new ServletException("JDBC Driver not found.", e);
        }
  }    }
------------------------------------------------------------------------------------------------------------
Output:
Home page:



Books details

BookID 1 status change from 'yes' to 'no' request made


Change done successfuly


Verify the change by seeing books details once again






Thursday, March 11, 2021

Java JAR file

a video tutorial  https://www.youtube.com/watch?v=QB19Wqimkq4

Core Java by Ratan

 Excellent video tutorials on core Java by the ' Java Ratan ' of DurgaSoft https://www.youtube.com/watch?v=gKqBPq3i62c&list=PLhChZSBQLZWGrORbbkpPuELxTTAFRoXYP

JDBC by Ratan https://www.youtube.com/watch?v=0X2gu-uD-NQ&list=PLd3UqWTnYXOlupbXFZhwjWhorMwscm0Hj

Web server Vs Application server

 There you go https://www.youtube.com/watch?v=BcmUOmvl1N8

Then what is Apache Tomcat? web server or application server? Tomcat

https://www.quora.com/Is-Tomcat-a-web-server-or-an-application-server

Tomcat is a web server (handles HTTP requests/responses) and web container (implements Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies) if we don't consider that we have all the add-ons and plug-ins made available through open source or commercially with Tomcat. Tomcat doesn't implement the complete Java EE API and doesn't have EJB container. Although we could run some applications in tomcat(one could easily argue that it is an application server) it will not be considered as fullfledged applcation server as it lacks some features of application server.

Apache is a web server, which can ideally handle static pages like HTML. 

To handle dynamic pages like php, we may need to load php module in apache configuration file.

Apache Tomcat is a combination of both web and application server, generally called as application server, can handle both static and dynamic pages. 

Of course, it needs java runtime environment as a prerequisite to run dynamic pages like servlets and jsps .



Wednesday, March 10, 2021

What is a web server?

 The term web server can refer to hardware or software, or both of them working together.

  1. On the hardware side, a web server is a computer that stores web server software and a website's component files. (for example, HTML documents, images, CSS stylesheets, and JavaScript files) A web server connects to the Internet and supports physical data interchange with other devices connected to the web.
  2. On the software side, a web server includes several parts that control how web users access hosted files. At a minimum, this is an HTTP server. An HTTP server is software that understands URLs (web addresses) and HTTP (the protocol your browser uses to view webpages). An HTTP server can be accessed through the domain names of the websites it stores, and it delivers the content of these hosted websites to the end user's device.

At the most basic level, whenever a browser needs a file that is hosted on a web server, the browser requests the file via HTTP. When the request reaches the correct (hardware) web server, the (software) HTTP server accepts the request, finds the requested document, and sends it back to the browser, also through HTTP. (If the server doesn't find the requested document, it returns a 404 response instead.)

Basic representation of a client/server connection through HTTP

To publish a website, you need either a static or a dynamic web server.

static web server, or stack, consists of a computer (hardware) with an HTTP server (software). We call it "static" because the server sends its hosted files as-is to your browser.

dynamic web server consists of a static web server plus extra software, most commonly an application server and a database. We call it "dynamic" because the application server updates the hosted files before sending content to your browser via the HTTP server.

For example, to produce the final webpages you see in the browser, the application server might fill an HTML template with content from a database. 

Sites like MDN or Wikipedia have thousands of webpages. Typically, these kinds of sites are composed of only a few HTML templates and a giant database, rather than thousands of static HTML documents. This setup makes it easier to maintain and deliver the content.


web server is server software, or a system of one or more computers dedicated to running this software, that can satisfy client HTTP requests on the public World Wide Web or also on private LANs and WANs.[1]

A web server can manage client HTTP requests for Web Resources related to one or more of its configured / served websites.

A web server usually receives incoming network HTTP requests and sends outgoing HTTP responses (one for each processed request), along with web contents, through transparent and / or encrypted TCP/IP connections (See also: HTTPS) which are started by client user agents before sending their HTTP request(s). Web servers may soon be able to handle other types of transport protocols for HTTP requests.

The purpose of a web server is to store and deliver web contents and / or web resources. Examples of web contents may be HTML filesXHTML filesimage files, style sheetsscripts, other types of generic files that may be downloaded by clients, etc.

Multiple web servers may be used for a high traffic website; here, Dell servers are installed together being used for the Wikimedia Foundation.

user agent, commonly a web browser or web crawler, initiates communication by making a request for a specific resource using HTTP and the server responds with the content of that resource or an error message if unable to do so. The resource is typically a real file on the server's secondary storage, but this is not necessarily the case and depends on how the web server and the website are implemented.

While the major function is to serve content, a full implementation of HTTP also includes ways of receiving content from clients. This feature is used for submitting web forms, including uploading of files.


computing, a server is a piece of computer hardware or software (computer program) that provides functionality for other programs or devices, called "clients". 

This architecture is called the client–server model. Servers can provide various functionalities, often called "services", such as sharing data or resources among multiple clients, or performing computation for a client. A single server can serve multiple clients, and a single client can use multiple servers. A client process may run on the same device or may connect over a network to a server on a different device.[1] Typical servers are database serversfile serversmail serversprint serversweb serversgame servers, and application servers.[2]

Client–server systems are today most frequently implemented by (and often identified with) the request–response model: a client sends a request to the server, which performs some action and sends a response back to the client, typically with a result or acknowledgment. Designating a computer as "server-class hardware" implies that it is specialized for running servers on it. This often implies that it is more powerful and reliable than standard personal computers, but alternatively, large computing clusters may be composed of many relatively simple, replaceable server components.

APPLICATION SERVER

An application server is a server that hosts applications.[1]

Application server frameworks are software frameworks for building application servers. An application server framework provides both facilities to create web applications and a server environment to run them.

An application server framework contains a comprehensive service layer model. It includes a set of components accessible to the software developer through a standard API defined for the platform itself. For Web applications, these components usually run in the same environment as their web server(s), and their main job is to support the construction of dynamic pages. However, many application servers do more than generate web pages: they implement services such as clustering, fail-over, and load-balancing, so developers can focus on implementing the business logic.[2]

In the case of Java application servers, the server behaves like an extended virtual machine for running applications, transparently handling connections to the database on one side, and, often, connections to the Web client on the other.[citation needed]


Java application servers[edit]

Java Platform, Enterprise Edition or Java EE (was J2EE) defines the core set of API and features of Java Application Servers.

The Java EE infrastructure is partitioned into logical containers.

Some Java Application Servers leave off many Java EE features like EJB and Java Message Service (JMS). Their focus is more on Java Servlets and JavaServer Pages.

There are many open source Java application servers that support Java EE.

Commercial Java application servers have been dominated by WebLogic Application Server by OracleWebSphere Application Server from IBM and the open source JBoss Enterprise Application Platform (JBoss EAP) by Red Hat.

A Java Server Page (JSP) executes in a web container. JSPs provide a way to create HTML pages by embedding references to the server logic within the page. HTML coders and Java programmers can work side by side by referencing each other's code from within their own.

The application servers mentioned above mainly serve web applications, and services via RMI, EJB, JMS and SOAP. Some application servers target networks other than web-based ones: Session Initiation Protocol servers, for instance, target telephony networks.

.NET Framework[edit]

Microsoft[edit]

Microsoft positions their middle-tier applications and services infrastructure in the Windows Server operating system and the .NET Framework technologies in the role of an application server.[4] The Windows Application Server role includes Internet Information Services (IIS) to provide web server support, the .NET Framework to provide application support, ASP.NET to provide server side scripting, COM+ for application component communication, Message Queuing for multithreaded processing, and the Windows Communication Foundation (WCF) for application communication.[5]

Third-party[edit]

  • Mono (a cross platform open-source implementation of .NET supporting nearly all its features, with the exception of Windows OS-specific features), sponsored by Microsoft and released under the MIT License

PHP application servers[edit]

PHP application servers are used for running and managing PHP applications.

Zend Server, built by Zend Technologies, provides application server functionality for the PHP-based applications.

appserver.io, built by TechDivision GmbH is a multithreaded application server for PHP written in PHP.

RoadRunner, built by Spiral Scout is a high-performance PHP application server, load-balancer, and process manager written in Golang.

Mobile application servers[edit]

A mobile app server is mobile middleware that makes back-end systems accessible to mobile application to support Mobile application development. Much like a web server that stores, processes, and delivers web pages to clients, a mobile app server bridges the gap from existing infrastructure to mobile devices.


Mobile application servers vs. application servers vs. web servers[edit]

Mobile application servers, Application servers, and web servers serve similar purposes: they are pieces of middleware that connect back-end systems to the users that need to access them, but the technology in each of the three differs. Application servers—developed before the ubiquity of web-based applications—expose back-end business logic through various protocols, sometimes including HTTP, and manage security, transaction processing, resource pooling, and messaging.[8] When web-based applications grew in popularity, application servers did not meet the needs of developers, and the webserver was created to fill the gap.[citation needed]

Web servers provide the caching and scaling functionality demanded by web access and not provided by application servers. They convert requests to static content and serve only HTTP content.[9] Over time, application servers and web servers have morphed from two previously distinct categories, blended features, and arguably have merged.[citation needed]

Mobile application servers are on a similar path.[citation needed] The emergence of mobile devices presents the need for functionality not anticipated by the developers of traditional application server developers, and mobile application servers fill this gap. They take care of the security, data management and off-line requirements not met by existing infrastructure, and present content exclusively in REST.

Over time, these three categories may fully merge and be available in a single product, but the root functions differ.


Source: Wikipedia

Common Gateway Interface

 In computing, Common Gateway Interface (CGI) is an interface specification that enables web servers to execute an external program, typically to process user requests.[1]

Such programs are often written in a scripting language and are commonly referred to as CGI scripts, but they may include compiled programs.[2]

A typical use case occurs when a Web user submits a Web form on a web page that uses CGI. 

The form's data is sent to the Web server within an HTTP request with URL denoting a CGI script. 


The Web server then launches the CGI script in a new computer process, passing the form data to it. 

The output of the CGI script, usually in the form of HTML, is returned by the script to the Web server, and the server relays it back to the browser as its response to the browser's request.[3]

Developed in the early 1990s, CGI was the earliest common method available that allowed a Web page to be interactive. Although still in use, CGI is relatively inefficient compared to newer technologies and has largely been replaced by them.[4]


Each Web server runs HTTP server software, which responds to requests from web browsers. Generally, the HTTP server has a directory (folder), which is designated as a document collection — files that can be sent to Web browsers connected to this server.[

For example, if the Web server has the domain name example.com, and its document collection is stored at /usr/local/apache/htdocs in the local file system, then the Web server will respond to a request for http://example.com/index.html by sending to the browser the (pre-written) file /usr/local/apache/htdocs/index.html.

A Web server allows its owner to configure which URLs shall be handled by which CGI scripts.

This is usually done by marking a new directory within the document collection as containing CGI scripts — its name is often cgi-bin. For example, /usr/local/apache/htdocs/cgi-bin could be designated as a CGI directory on the Web server. When a Web browser requests a URL that points to a file within the CGI directory (e.g., http://example.com/cgi-bin/printenv.pl/with/additional/path?and=a&query=string), then, instead of simply sending that file (/usr/local/apache/htdocs/cgi-bin/printenv.pl) to the Web browser, the HTTP server runs the specified script and passes the output of the script to the Web browser. That is, anything that the script sends to standard output is passed to the Web client instead of being shown on-screen in a terminal window.


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

Sacred Thought

26 April 2024  Dear friends, I write the explanation of two verses of Geets for all of you, I hope you all will like it and benefit from it....