Architecture, Building Blocks.
Kush Asrani , Krsna Chandarana, Manisha Chauhan, Soham Das
specialized computer system or software application designed to manage and provide resources, services, or data to other computers, known as clients, over a network.
A JSP application typically runs on an application server, which processes JSP files and generates dynamic content.
web server
small scale application server for JSP and Servlets
full stack application server
CGI (Common Gateway Interface)
Servlets
JSP (JavaServer Pages)
concurrent requests to the server are handled by threads,
A generic servlet is a protocol independent Servlet that should always override the service() method to handle the client request.
HTTP Servlet doesn’t override the service() method. Instead it overrides the doGet() method or doPost() method or both. The doGet() method is used for getting the information from server while the doPost() method is used for sending information to the server.
To create Java Servlets, we need to use Servlet API which contains all the necessary interfaces and classes. Servlet API has 2 packages namely
used for serving protocol-less requests. It contains the interfaces and classes that every servlet must implements and extends respectively.
used for the development of servlets that use the HTTP protocol.
doGet() and doPost()).Loading and Instantiation
init() method is executed.
service() method processes requests.
destroy() method cleans up resources.
Text
JavaServer Pages is a server-side technology used to create dynamically generated web pages based on HTML, XML or other document types.
JSP allows developers to insert Java code into their pages, simplifying the process of creating complex web applications.
Once, you have a JSP capable web-server or application server, save your files as .jsp instead of.html and access the files from your browser.
JSP Page
Servlet
Web Container (like Tomcat)
HTTP Request & Response Objects
A file containing HTML mixed with JSP tags (Java code).
The JSP page is translated into a Servlet (Java class).
Manages the lifecycle of JSPs and servlets, like translation, compilation, and execution.
Communication between client (browser) and server, where requests are processed and responses are sent back.
The JSP Lifecycle consists of phases a JSP page goes through from creation to destruction.
Key Stages:
1. Translation
2. Compilation
3. Initialization
4. Request Handling
5. Destruction
Translation Phase
JSP is translated into a Servlet.
Compilation Phase
Servlet is compiled into Java bytecode.
Initialization Phase
This is where any resource initialization is performed.
Destruction Phase
This is the process where the cleanup of resources begin.
Resource Handling Phase
The request from the client is processed.
JavaServer Pages (JSP) building blocks are the fundamental components that enable developers to create dynamic web content.
JSP has four main building blocks:
These building blocks work together to allow developers to create dynamic, maintainable, and interactive web applications. Understanding each component is crucial for effective JSP development and ensures that applications are robust and scalable.
JSP Pages
containing HTML along with embedded Java code.
Directives
Provide global information about an entire JSP page
Scriptlets
Blocks of Java code embedded within a JSP page, enclosed in <% %> tags.
Comments
Help document code for developers.
Expressions
To output data directly to the client.
Directive tags provide general information, overall properties about the JSP page to the JSP engine.
A directive tag always starts with <%@ and ends with %>.
There are 3 types of directives: page, include, and taglib.
<%@ page language=”java” %>
informs the JSP engine that Java will be used as scripting language in our JSP page
<%@ include file=”test.jsp” %>
tells the JSP engine to include the contents of another file (HTML, JSP, etc) into the current file.
Declarations declare and define variables and methods that can be used in the JSP page.
A declaration always starts with
<%! and ends with %>.
Scriptlets are used to embed any Java code fragments in the JSP page.
For example: <% i++; %>
the value of i is incremented each time the page is requested.
Expression tags are used as a shortcut to print values in the output HTML in a JSP page. Syntax is:
<%= variable %>
The variable denotes the variable value that is needed to be printed in the output HTML page.
Comments are used for documentation purposes but do not affect the output of the JSP page in any way. The syntax of a JSP comment is:
<%-- comment --%>
While both JSP and Servlets are used in Java web applications, JSP allows for easier page design by embedding Java code within HTML..
Servlets are Java classes that handle requests and responses, offering more control at the code level, but require more complex writing for web page creation.
Apache Tomcat is a free and open-source implementation of the Jakarta Servlet, Jakarta Expression Language, and WebSocket technologies. It provides a "pure Java" HTTP web server environment in which Java code can also run. Thus it is a Java web application server, although not a full JEE application server.
It is a web container, which is a part of web server or application server that manages the execution of Servlets and JSP. It provides the environment required for components to run, including request handling, response generation, and lifecycle management.