Chapter 3 Web Programming PDF

Document Details

ExpansiveMossAgate7745

Uploaded by ExpansiveMossAgate7745

College of Computer Science, Information & Technology, Department of Computer Science

Raj Kumar Masih

Tags

web programming java programming web applications computer science

Summary

This document provides an introduction to web programming, specifically Java-based web applications. It outlines the components of a web application, distinguishing between static and dynamic pages. It also explains the role of servlets and Java Server Pages (JSPs) in dynamic content generation.

Full Transcript

Chapter - 3 College of Computer Science Information & Technology Department of Computer Science (CS) Preapared by: Raj Kumar Masih A web application is a set of web pages that are geneated in response to user requests. The internet has many different types of web applications, such as search engine...

Chapter - 3 College of Computer Science Information & Technology Department of Computer Science (CS) Preapared by: Raj Kumar Masih A web application is a set of web pages that are geneated in response to user requests. The internet has many different types of web applications, such as search engines, online stores, auctions, news sites, discussion groups and games. THE COMPONENETS OF WEB APPLICATION The basic components that make up a web application. Because a web application is a type of client/server application, the components of a web application are stored on either the client computer or the server computer. vThe web application itself is stored on the server computer. This computer runs web server software that enables it to send web pages to web browsers. Although there are many web servers, the most popular one for Java web applications is the Apache Software Foundation’s Apache HTTP Server, which is usally just calle Apache. vThe most web applications work with data that’s stored in a database, most servers also run a database management system (DBMS). Two of the most popular for Java development are Oracle and MySQL. vThe DBMS doesn’t have to necessarily run on the same server as the web server software. § Static Web Pages mean that the information on the these pages never change according to the user’s choice but rather can be switched from one page to another. The static web pages are like the News papers which can be shifted from one page to another. § HTML (Hypertext Markup Language) is the language that the browser renders to the web pages that make up a web application’s user interface. Many of these web pages are static web pages, which are the same each time they are viewed. § Theprocess begins when a user at a web browser’s address box or when the user clicks in a link that leads to another page. In either case, the web browser uses a standard Internet protocol knonw as Hypertext Transfer Protocol (HTTP) to send a request known as an HTTP request to the web site’s server. The Dynamic Web Pages are the web pages which changes according to the user’s choice or cuztomized according to the users. Example - eCommers The changes of these pages are based on the parameters that are sent through the web application from the web page to a web server. Then, the web server generates the dynamic web page and sends the HTML for it back to the browser. This request contains the address of the next web page along with any data entered by the user, when web server receive this request and then determines that it is a request for a dynamic web page. The primary software components for a Java web application that we need to understand is that why the server must run web server software. Web Server Software - A program that uses HTTP for serving files that create web pages for users in response to their requests that are sent by the HTTP clients of their computer is called as a web server. In a simple words, a web server is an Internet server that responds to HTTP requests for delivering content and services. § To run a Java application, the server must also run a software product known as a Servlet/JSP engine, or Servlet/JSP container. This software allows a web server to run servlet and JSPs. § Sun’s Java Enterprise Edition (Java EE) specification describes how a servlet/JSP engin should interact with a web server. § Though there are several Web Server available but the Tomcat is a free, open-source servlet/JSP engine that was developed by the Jakarta project at the Apache Software Foundation. This engine is the official reference implemnentation of the servlet/JSP specification set forth by Sun, and it is one of the most popular Servlet/JSP engines. § For a Servlet/JSP engine to work properly, the engine must be able to access the Java Development Kit (JDK) that comes as a part of the Java Standard Edition (Java SE). § The JDK contains the Java compiler and the core classess for working with Java. It also contains the Java Runtime Environment (JRE). that’s necessary for running compiled Java classes. The JSP is the acronym of Java Server Pages. Java Server Pages (JSP) technology enables us to mix regular, static HTML with dynamically generated content from servlets. § JSP requires extensive Java programming, though it is easier to write the Java code with a servlet. In practice web designers often write the HTML portions of the JSPs, while web programmers write the Java portions. § When a JSP is requested for the first time, the JSP engine (which is a part of the Servlet/JSP engine) converts the JSP code into the Servlet engine, which runs it. For subsequent requests, the JSP engine runs the servlet that corresponds to the JSP. § A Servlet is a Java class that runs on a server and does the processing for the dynamic web pages of a web application. § That is why servlet for a web application are written by web programmers, not web designers. § After the processing is done, a Servlet can return HTML code to the browser by using the pritln method of an out object. § The Servlet has three major methods known as the skeleton of Servlet - 1) Init( ) - To start or Initiate the Servelet. 2) Service( ) - It containts two major methods. a) doGet( ) b) doPost( ) 3) Destroy( ) - Stops the Servlet engine. A pattern is a standard approach that is used by programmers to solve common programming problems. One of these patterns is the Model-View-Controller pattern (MVC pattern). It has three layers - MODEL - It defines the business layer of the application. This layer is usually implemented by JavaBeans. This type of class defines the data for the busness object and provides the methods that do the buiness processing. VIEW - It defines the presentation layer of the application. Since it is cumbersome to use a servlet to send HTML to a browser, an MVC application uses HTML documents or JSPs to present the view to the browser. CONTROLLER - It manages the flow of the application, and this work is done by servlets. To start, a servlet usually reads any aparameters that are available from the request, which typically comes from the View. Then, if necessary, the servlet updates the Model and saves it to the data store. This architecture uses thre layers - 1) Presentation /User Interface Layer It consists of HTML pages and JSPs. Typically, a web designer will work on the HTML stored in these pages to create the look and feel of the user interface. Later a Java programmer may need to edit these pages so they may work properly with the servlets of the application. 2) Business Rules Layer It uses servlets to control the flow of the application. These servlets may call other Java classes to store or retrive data from a database and they may forward the results to a JSP or to another servlet. Java programmers often uses a special type of Java class known as a JavaBean to temporarily store and process data. 3) Data Access Layer The data layer works with data is usually stored in a relational database. However, this data can also be stored in text files and binary files. In addition, the data for an application can be stored in an Extensible Markup Language (XML) file. 1) JSP Vs ASP (Active Server Pages) - ASP is a competing technology from Microsoft. The advantages of JSP are two fold. 1) The dynamic part is written in Java, not VBScript or another ASP-spesific language, so it is more powerful and better suited to complex applications that require reusable components. 2) JSP is poratble to other operating systems and Web servers; we are not locked into Windows and IIS. 2) JSP Vs PHP (Personal Home Page) - PHP is a free, open-source HTML-embedded scripting language that is somewhat similar to both ASP and JSP. The advantage of JSP is that the dynamic part is written in Java. 3) JSP Vs Server-Side Includes (SSI) - SSI is a widely supported technology for inserting externally defined pieces into a static Web page. JSP is better because you have a richer set of tools for building that external piece and have more options regarding the stage of the HTTP response at which the piece actually gets inserted. 4) JSP Vs Static HTML - Regular HTML, of course, cannot contain dynamic information, so static HTML pages cannot be based upon user input or serv-side data sources. JSP is so easy and convenient that it is quite reasonable to augment HTML pages that only benefit slightly by the insertion of dynamic data. Previously, the difficulty of using dynamic data precluded its use in all but the most valuable instances.

Use Quizgecko on...
Browser
Browser