0% found this document useful (0 votes)
27 views4 pages

Webtechmini

The document provides an overview of JavaScript and Java Servlets, detailing data types, variables, operators, and control structures in JavaScript, as well as servlet lifecycle, request handling, and session management in Java. It explains the differences between dynamic and active web pages, highlighting the role of JavaScript in creating interactive content and the use of servlets for generating dynamic HTML responses. Additionally, it discusses the importance of cookies and sessions in maintaining user state across web applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views4 pages

Webtechmini

The document provides an overview of JavaScript and Java Servlets, detailing data types, variables, operators, and control structures in JavaScript, as well as servlet lifecycle, request handling, and session management in Java. It explains the differences between dynamic and active web pages, highlighting the role of JavaScript in creating interactive content and the use of servlets for generating dynamic HTML responses. Additionally, it discusses the importance of cookies and sessions in maintaining user state across web applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1 2 3

JavaScript: These store collections of values or complex structures. console.log(z);


JavaScript is a high-level, interpreted, object-oriented programming Data
language primarily used for web development to create dynamic and Description Example 3. JavaScript Operators
Type
interactive web pages. A collection of key-value JavaScript provides various operators for performing operations.
Object {name: "Alice", age: 25} A. Arithmetic Operators
pairs.
1. JavaScript Data Types Array An ordered list of values. ["Apple", "Banana", "Mango"] Used for mathematical calculations.
In JavaScript, data types are divided into two categories: Operator Description Example (a = 10, b = 5) Result
function greet() {
A. Primitive Data Types (Immutable, Stored by Value) Function A block of reusable code. + Addition a+b 15
console.log("Hello"); }
These store single values and are not objects. - Subtraction a-b 5
Example of Non-Primitive Data Types:
Data Type Description Example
let person = {name: "Alice", age: 25}; // Object * Multiplication a*b 50
A sequence of characters let fruits = ["Apple", "Banana", "Mango"]; // Array
String "Hello, World!" / Division a/b 2
enclosed in "" or ''. function greet() { console.log("Hello!"); } // Function % Modulus (Remainder) a % b 0
Numeric values (integers or
Number 42, 3.14 ++ Increment ++a 11
floating-point numbers). 2. JavaScript Variables
-- Decrement --b 4
Boolean Represents true or false values. true, false A variable is a container for storing data. JavaScript provides three
B. Comparison Operators
A variable that has been declared ways to declare variables:
Undefined let x; Used to compare values and return a Boolean (true or false).
but not assigned a value. A. Using var (Old method, function-scoped)
console.log(10 == "10"); // true (loose equality)
Represents an intentional empty Can be re-declared and updated.
Null let y = null; console.log(10 === "10"); // false (strict equality)
value. Not block-scoped (ignores {} blocks).
console.log(10 > 5); // true
BigInt Used for very large integers. 1234567890123456789n var x = 10;
console.log(10 != 5); // true
var x = 20; // Allowed (Re-declaration)
Unique and immutable primitive C. Logical Operators
Symbol let id = Symbol("id"); console.log(x); // 20
value. Used for logical conditions.
B. Using let (Modern method, block-scoped)
Example of Primitive Data Types: console.log(true && false); // false (AND)
Cannot be re-declared, but can be updated.
let name = "Alice"; // String console.log(true || false); // true (OR)
Block-scoped (respects {} blocks).
let age = 25; // Number console.log(!true); // false (NOT)
let y = 30;
let isStudent = false; // Boolean D. Ternary Operator
y = 40; // Allowed (Update)
let city; // Undefined Shorthand for if...else.
console.log(y); // 40
let car = null; // Null let age = 20;
C. Using const (Constant, cannot be changed)
let bigNumber = 123n; // BigInt let result = (age >= 18) ? "Adult" : "Minor";
Cannot be re-declared or updated.
let uniqueID = Symbol("id"); // Symbol console.log(result); // "Adult"
Must be initialized when declared.
const z = 50;
B. Non-Primitive Data Types (Mutable, Stored by Reference) 4. Conditional Statements
// z = 60; // Error: Assignment to constant variable

4 5 6

Used for decision-making in programs. console.log(today.getFullYear()); // 2025 The Servlet Container provides:
A. if-else Statement console.log(today.getMonth() + 1); // 3 (Month is 0-based) Lifecycle Management – Controls the servlet’s execution (initialization,
let num = 10; console.log(today.getDate()); // 21 execution, and destruction).
if (num > 0) { Request Handling – Manages client HTTP requests and responses.
console.log("Positive number"); 7. String Object Concurrency Management – Allows multiple users to access servlets
} else { Strings are sequences of characters. simultaneously.
console.log("Negative number"); let str = "Hello, World!"; Session Management – Tracks user sessions using cookies and session
} console.log(str.length); // 13 IDs.
B. switch Statement console.log(str.toUpperCase()); // "HELLO, WORLD!" Role of Servlets in Web Applications
let fruit = "apple"; console.log(str.toLowerCase()); // "hello, world!" Servlets act as the middleware between the client (browser) and the
switch (fruit) { console.log(str.indexOf("World")); // 7 server. Their key responsibilities include:
case "apple": console.log(str.replace("World", "JS")); // "Hello, JS!" Handling client HTTP requests (GET, POST, etc.).
console.log("Apple selected."); Generating dynamic HTML content (unlike static HTML pages).
break; Conclusion Connecting with databases and APIs to fetch/store data.
case "banana": JavaScript provides various data types, variables, and operators for Managing user sessions for authentication and personalization.
console.log("Banana selected."); computation. Processing form submissions from web pages.
break; Java Servlet – Detailed Theoretical Explanation
default: Introduction to Java Servlets 2. HTML Support in Servlets
console.log("Unknown fruit."); A Java Servlet is a server-side Java program that extends the Servlets are capable of dynamically generating HTML content and
} capabilities of web servers by handling client requests, processing sending it as a response to the client. They use the
them, and generating dynamic web responses. Servlets are an integral HttpServletResponse class to write HTML code.
5. Array Object part of Java’s Java EE (Enterprise Edition) platform and work with HTTP Example of HTML Response in Servlet
An array stores multiple values in an ordered list. protocols in a web environment. import java.io.*;
let fruits = ["Apple", "Banana", "Mango"]; import javax.servlet.*;
console.log(fruits[0]); // Apple 1. Servlet Environment and Role import javax.servlet.http.*;
fruits.push("Orange"); // Add element Servlet Environment
fruits.pop(); // Remove last element A Java Servlet operates within a Servlet Container (also known as a public class HelloServlet extends HttpServlet {
console.log(fruits.length); // 3 Web Container), which is part of a web server or application server. public void doGet(HttpServletRequest request, HttpServletResponse
Popular servlet containers include: response) throws ServletException, IOException {
6. Date Object Apache Tomcat response.setContentType("text/html"); // Set response type
The Date object is used to handle date and time. GlassFish PrintWriter out = response.getWriter(); // Get writer object
let today = new Date(); Jetty out.println("<html><body>");
console.log(today.toDateString()); // "Fri Mar 21 2025" JBoss/WildFly out.println("<h1>Welcome to Java Servlet</h1>");

7 8 9

out.println("</body></html>"); Interface/Class Description public void doGet(HttpServletRequest request, HttpServletResponse


} Extends ServletResponse, used for sending HTTP response) throws ServletException, IOException {
} HttpServletResponse response.setContentType("text/html");
responses.
Key Features of HTML Support in Servlets HttpSession Used for managing user sessions. PrintWriter out = response.getWriter();
Servlets generate dynamic HTML pages based on user input or out.println("<h1>Handling Request</h1>");
Represents an HTTP cookie for storing small
database content. Cookie }
pieces of user data.
HTML content is sent using PrintWriter through the response object.
Servlets can embed CSS and JavaScript within the HTML response for // Destroy
styling and interactivity. 4. Servlet Life Cycle public void destroy() {
A Java Servlet undergoes three major stages in its life cycle, managed System.out.println("Servlet Destroyed");
3. Servlet API by the Servlet Container. }
A. Servlet Packages A. Stages of the Servlet Life Cycle }
Java Servlets rely on the Java Servlet API, which consists of two key Stage Description
packages: Loading and The servlet is loaded into memory and initialized 5. Cookies and Sessions
Package Description Initialization (init()) when the server starts or upon first request. A. Cookies in Servlets
javax.servlet Contains core servlet classes and interfaces. Handling Requests The servlet processes client requests using A cookie is a small piece of data stored on the client’s browser to
Provides HTTP-specific functionality, including (service()) methods like doGet() and doPost(). maintain user state.
javax.servlet.http The servlet is removed from memory when the Creating and Sending a Cookie
session and cookie management. Destroying the
server shuts down or the application is Cookie cookie = new Cookie("username", "JohnDoe");
B. Important Interfaces and Classes in Servlet API Servlet (destroy())
undeployed. cookie.setMaxAge(3600); // 1 hour expiry
Interface/Class Description
B. Servlet Life Cycle Methods response.addCookie(cookie); // Send cookie to client
Interface that defines basic methods (init(), Retrieving Cookies in a Servlet
Servlet import java.io.*;
service(), destroy()). Cookie[] cookies = request.getCookies();
import javax.servlet.*;
GenericServlet Provides a simple implementation of Servlet. import javax.servlet.http.*; for (Cookie c : cookies) {
Extends GenericServlet and is used for HTTP- System.out.println("Cookie: " + c.getName() + "=" + c.getValue());
HttpServlet
based servlets. public class LifecycleServlet extends HttpServlet { }
Allows retrieval of request data (parameters, Deleting a Cookie
ServletRequest Cookie cookie = new Cookie("username", "");
headers, etc.). // Initialization
Allows sending responses to clients (HTML, JSON, public void init() throws ServletException { cookie.setMaxAge(0); // Expire immediately
ServletResponse response.addCookie(cookie);
etc.). System.out.println("Servlet Initialized");
Extends ServletRequest, providing additional } B. Sessions in Servlets
HttpServletRequest A session stores user-specific data on the server and assigns a unique
methods for handling HTTP requests.
// Request Handling session ID.
10 11 12

Creating a Session JavaScript – Adds interactivity and event handling.


HttpSession session = request.getSession(); DOM (Document Object Model) – Allows dynamic content
session.setAttribute("username", "JohnDoe"); manipulation.
Retrieving a Session Attribute Example of DHTML: Changing Text Dynamically
String user = (String) session.getAttribute("username"); <!DOCTYPE html>
System.out.println("User: " + user); <html>
Destroying a Session <head>
session.invalidate(); // End session <title>DHTML Example</title>
Dynamic Web Pages & Active Web Pages – Detailed <script>
Comparison: Cookies vs. Sessions Explanation function changeText() {
Feature Cookies Sessions 1. Dynamic Web Pages document.getElementById("text").innerHTML = "Text
Storage A. Need for Dynamic Web Pages Changed!";
Stored in the client’s browser Stored on the server }
Location A dynamic web page is a web page that changes content dynamically
Data Size Limited (4KB per cookie) Large based on user interaction, database updates, or real-time data </script>
fetching. Unlike static web pages, which remain unchanged unless </head>
Less secure (can be modified by
Security More secure manually modified, dynamic pages offer interactivity and personalized <body>
client)
content. <p id="text">Original Text</p>
Can persist beyond browser Ends when session <button onclick="changeText()">Click Me</button>
Expiration Reasons for Using Dynamic Web Pages:
session expires </body>
User Interaction – Allows forms, live chat, and interactive content.
Database Connectivity – Enables fetching and displaying live data from </html>
Conclusion Features of DHTML:
databases.
Java Servlets enable dynamic web applications by handling HTTP Enables dynamic content updates without refreshing the page.
Real-Time Content Updates – Used in news portals, social media feeds,
requests. Uses JavaScript and CSS for animations.
and stock market updates.
Servlets run inside a Servlet Container and support HTML content Provides interactive behavior like form validation, dropdowns, and
Better User Experience – Enhances engagement with animations and
generation. event-driven actions.
real-time updates.
Servlet API provides essential classes (HttpServlet, HttpSession,
Scalability – Efficient for large-scale applications (e.g., e-commerce,
Cookie) for handling requests and responses. C. Cascading Style Sheets (CSS)
blogs).
The servlet lifecycle includes initialization (init()), request handling CSS is a styling language used to design and format web pages by
(service()), and destruction (destroy()). controlling the layout, colors, fonts, and responsiveness.
B. Overview of DHTML (Dynamic HTML)
Cookies and Sessions help in maintaining user state across multiple Types of CSS:
DHTML (Dynamic HTML) is not a separate technology but a
requests. Inline CSS – Applied within an HTML tag.
combination of:
This theoretical understanding of Java Servlets is essential for building <p style="color: red;">This is a red paragraph.</p>
HTML – Defines webpage structure.
efficient and scalable web applications using Java! Internal CSS – Defined within a <style> tag inside the HTML file.
CSS (Cascading Style Sheets) – Controls the appearance of elements.

13 14 15

<style> Unlike traditional dynamic web pages, active pages execute scripts Client-side execution (no server dependency).
p { color: blue; } directly within the browser or via server communication. Graphical capabilities for interactive UI elements.
</style> Reasons for Active Web Pages: Cross-platform compatibility (runs on any system with Java).
External CSS – Stored in a separate .css file and linked using <link> tag. Live user interaction – Mouse events, keystrokes, animations. Limited access to system resources for security reasons.
p { color: green; } Real-time updates – Weather updates, live scores.
Key Features of CSS: Reduced server load – Some processing is handled on the client side. C. Comparison: Dynamic vs. Active Web Pages
Separation of content and design (better maintainability). Better performance – Avoids frequent full-page reloads. Feature Dynamic Web Pages Active Web Pages
Reusability (single CSS file for multiple pages). Execution Server-side and client-
Enhances performance (reduces HTML complexity). B. Java Applet Life Cycle Mostly client-side
Location side
Responsive Design (supports different screen sizes). A Java Applet is a small Java program that runs inside a web browser Examples PHP, JSP, ASP.NET, AJAX Java Applets, JavaScript
or an applet viewer. It is a client-side technology that enhances web
Interactivity Moderate High (real-time execution)
D. Comparative Study of Different Technologies for Dynamic Page interactivity.
Creation Applet Life Cycle Stages: Relies on server Runs on client-side,
Performance
Initialization (init()) responses reducing load
Technology Description Use Case
Called when the applet is first loaded. More secure (handled on Less secure (executed on
Client-side scripting for Forms, animations, Security
JavaScript Starting (start()) server) client)
interactivity event handling
Asynchronous updates Live search, chat Executed after init(), starts applet execution.
AJAX Running (paint(Graphics g)) Conclusion
without page reload applications
Handles graphical rendering and user interaction. Dynamic Web Pages provide real-time interactivity using DHTML, CSS,
Server-side scripting for Form handling, JavaScript, and server-side scripting.
PHP Stopping (stop())
backend processing authentication DHTML combines HTML, CSS, JavaScript, and DOM to create
Called when the applet is paused or navigated away.
Microsoft’s server-side Destroying (destroy()) interactive content.
ASP.NET Enterprise applications
technology Frees resources before applet termination. CSS plays a crucial role in enhancing the presentation and
JSP (Java Server Java-based web scripting E-commerce, banking Example of Java Applet responsiveness of web pages.
Pages) language apps import java.applet.Applet; Various technologies (JavaScript, PHP, JSP, ASP.NET) enable dynamic
ReactJS / JavaScript frameworks for Single Page Applications import java.awt.Graphics; page creation, each with its own advantages.
Angular UI development (SPAs) Active Web Pages focus on real-time execution on the client-side for
public class MyApplet extends Applet { better interactivity.
2. Active Web Pages public void paint(Graphics g) { Java Applets were traditionally used for graphical and interactive
A. Need for Active Web Pages g.drawString("Hello, Applet!", 50, 50); content but are now largely replaced by modern technologies like
Active web pages involve real-time client-side or server-side } JavaScript, React, and WebAssembly.
execution to provide dynamic user interaction and data processing. } J2EE and XML – Detailed Theoretical Explanation
Key Features of Java Applets: 1. J2EE Overview

16 17 18

J2EE (Java 2 Platform, Enterprise Edition) is a platform for developing Transaction Management – Ensures data consistency. public class RMIExample extends UnicastRemoteObject implements
and deploying enterprise-level applications. It extends Java SE Security – Role-based access control. RMIInterface {
(Standard Edition) with additional capabilities for building web Scalability – Supports distributed systems. public RMIExample() throws RemoteException {}
applications, distributed systems, and enterprise software. Persistence – Seamless database interaction. public String sayHello() { return "Hello from RMI"; }
A. J2EE Web Services Overview }
Web services in J2EE allow applications to communicate over the C. EJB vs. JavaBeans Advantages of RMI:
internet using standard protocols such as SOAP (Simple Object Access EJB (Enterprise Allows distributed computing in Java applications.
Protocol) and REST (Representational State Transfer). Feature JavaBeans Supports object serialization for sending data over the network.
JavaBeans)
Types of J2EE Web Services: Used for enterprise-level Used for simple data
SOAP-based Web Services Scope E. Basics of JNI (Java Native Interface)
applications handling
Uses XML for structured messaging. Runs in an application JNI (Java Native Interface) allows Java programs to interact with
Based on WSDL (Web Services Description Language). Architecture Runs in a local JVM native code written in C or C++.
server
Example: Banking and financial transactions. Why Use JNI?
Inbuilt security
RESTful Web Services Security No security by default To access low-level system resources (hardware, OS).
mechanisms
Uses HTTP methods (GET, POST, PUT, DELETE). To integrate Java with legacy applications written in C/C++.
Data exchanged in JSON or XML format. Transaction Supports distributed To improve performance by using native code for computation-heavy
No transaction support
Example: Social media APIs (Facebook, Twitter). Support transactions tasks.
Technologies Used in J2EE Web Services: Uses JPA for database Requires manual Steps in Using JNI:
Persistence
JAX-RPC (Java API for XML-based Remote Procedure Call) operations database integration Declare native methods in Java
JAX-WS (Java API for XML Web Services) Implement them in C/C++
JAX-RS (Java API for RESTful Web Services) D. Basics of RMI (Remote Method Invocation) Load the native library in Java using System.loadLibrary()
RMI (Remote Method Invocation) allows Java applications to invoke Example of JNI Method Declaration in Java:
B. Basics of Enterprise JavaBeans (EJB) methods on remote objects located on different JVMs. It is useful for public class JNIExample {
Enterprise JavaBeans (EJB) is a server-side component model used in distributed computing. public native void sayHello(); // Native method
J2EE for building scalable, secure, and transactional enterprise Working of RMI: static { System.loadLibrary("NativeLibrary"); } // Load native library
applications. Define a Remote Interface – Specifies methods to be called remotely. }
Types of EJBs: Implement the Remote Interface – Provide the actual implementation.
Session Beans – Handles business logic; can be Stateless or Stateful. Register the Object with RMI Registry – Makes it accessible to clients. 2. XML (Extensible Markup Language)
Entity Beans – Represents database entities (deprecated in favor of Client Calls the Remote Method – Uses RMI stub to invoke methods. XML (Extensible Markup Language) is a markup language used to store
JPA). Example of RMI Server Code: and transport data in a structured and human-readable format.
Message-Driven Beans (MDBs) – Handles asynchronous messaging import java.rmi.*; A. Basics of XML
(JMS). import java.rmi.server.*; Self-descriptive format – Data is stored in a hierarchical structure.
Key Features of EJB:
19 20 21

Platform-independent – Works across different programming <!ELEMENT title (#PCDATA)> HTML (HyperText Markup Language) is the standard language for
languages. <!ELEMENT author (#PCDATA)> creating web pages. It uses elements to structure content using tags
Extensible – Custom tags can be created. ]> enclosed in angle brackets (< >).
Used in – Web services, configuration files, data exchange, etc. Uses of DTD: Basic HTML Structure:
Example of an XML File: Ensures validity of XML documents. <!DOCTYPE html>
<?xml version="1.0" encoding="UTF-8"?> Defines rules for elements and attributes. <html>
<student> <head>
<name>John Doe</name> D. XML Parsers <title>My First Web Page</title>
<age>22</age> An XML Parser processes XML documents and makes the data </head>
<course>B.Tech</course> available to programs. <body>
</student> Types of XML Parsers: <h1>Welcome to HTML</h1>
DOM (Document Object Model) Parser <p>This is a paragraph in HTML.</p>
B. XML Elements and Attributes Loads the entire XML document into memory. </body>
Elements in XML: Allows tree-based manipulation. </html>
The core building blocks of an XML document. Example: Used in complex XML structures like web services. <!DOCTYPE html> → Defines the document type (HTML5).
Represented as opening and closing tags (<tag>content</tag>). SAX (Simple API for XML) Parser <html> → Root element of the HTML document.
Example of XML Elements: Processes XML sequentially (event-driven). <head> → Contains metadata (title, styles, scripts).
<book> Uses less memory, making it suitable for large XML files. <body> → Contains the visible content of the web page.
<title>Web Technology</title> Example: Used in streaming data processing.
<author>John Smith</author> B. Document Body and Different Tags
</book> E. Sequential vs. Tree-Based Parsing Approach The document body (<body>) contains all visible elements on a web
Attributes in XML: Approach Description Example page, such as headings, paragraphs, links, images, and tables.
Store additional metadata within elements. Sequential Reads XML line by line, event- Commonly Used HTML Tags
Defined inside the opening tag. Data streaming Tag Description
(SAX) driven
Example of XML Attributes: Tree-Based Loads entire XML into a tree Complex XML Headings (H1 is the largest, H6 is the
<book title="Web Technology" author="John Smith" /> <h1> to <h6>
(DOM) structure manipulation smallest)
<p> Paragraph
C. Document Type Definition (DTD)
Introduction to HTML and Web Technologies – Detailed Theoretical <a href="URL"> Hyperlink
DTD (Document Type Definition) defines the structure and rules for an
Explanation <img src="image.jpg"
XML document. Image
1. Introduction to HTML alt="Text">
Example of DTD:
A. Fundamentals of HTML Elements <ul> <li> Unordered list (bulleted)
<!DOCTYPE book [
<!ELEMENT book (title, author)> <ol> <li> Ordered list (numbered)

22 23 24

Tag Description <th>Name</th> </form>


<table> Table <th>Age</th> <input> → Text fields, checkboxes, radio buttons
<form> Form for user input </tr> <select> → Dropdown menus
<tr> <textarea> → Multi-line input
<td>John</td>
C. Sections and Text Formatting
<td>25</td> 2. Web Pages: Types and Issues
HTML allows structuring sections using tags like <header>, <section>,
</tr> A. Types of Web Pages
<footer>, etc.
</table> Static Web Pages
Bold Text: <b>Bold</b> or <strong>Strong</strong>
<th> → Table header Content does not change dynamically.
Italic Text: <i>Italic</i> or <em>Emphasized</em>
<td> → Table data Created using HTML and CSS only.
Underlined Text: <u>Underline</u>
<tr> → Table row Example: Company About Us pages.
Dynamic Web Pages
D. Hyperlinks
G. Colors and Images in HTML Content changes based on user interaction.
Hyperlinks allow users to navigate between web pages using the <a>
Adding Color: Uses JavaScript, PHP, Python, or databases.
tag.
<p style="color:blue;">This is blue text.</p> Example: Facebook, Twitter.
<a href="https://www.google.com">Visit Google</a>
Adding an Image:
The href attribute specifies the URL.
<img src="image.jpg" alt="Sample Image" width="200"> B. Web Page Issues
Slow loading speed (due to large images, scripts).
E. Lists in HTML
H. Frames and Frameset Browser compatibility (different browsers render pages differently).
Unordered List (<ul>)
Frames allow dividing a browser window into multiple sections. SEO challenges (search engines may not index certain content
<ul>
<frameset cols="50%, 50%"> properly).
<li>Item 1</li>
<frame src="page1.html">
<li>Item 2</li>
<frame src="page2.html"> 3. Web Architecture and Technologies
</ul>
</frameset> A. Tiers in Web Architecture
Ordered List (<ol>)
Frames are outdated in modern web design due to accessibility and 1-Tier Architecture:
<ol>
SEO issues. All processing is done on one system (Example: Personal websites).
<li>First Item</li>
2-Tier Architecture:
<li>Second Item</li>
I. Forms in HTML Client (Browser) ↔ Server (Database & Processing).
</ol>
Forms collect user input using various form elements. Example: Simple login systems.
<form action="submit.php" method="POST"> 3-Tier Architecture:
F. Tables in HTML
Name: <input type="text" name="name"><br> Client ↔ Application Server ↔ Database Server.
Tables organize data in rows and columns.
Email: <input type="email" name="email"><br> Example: E-commerce websites.
<table border="1">
<input type="submit" value="Submit">
<tr>

25 26 27

B. Comparison: Microsoft vs. Java Technologies <body>Hello World!</body> Database Tier: A database that stores application data, accessed via
Feature Microsoft (ASP.NET) Java (J2EE) </html> JDBC (Java Database Connectivity).
Platform Windows-based Cross-platform JSP Processing Flow
Ease of More complex but D. Universal Resource Locator (URL) Client sends a request to a JSP page.
Easier for beginners A URL (Uniform Resource Locator) uniquely identifies a web resource. The JSP engine converts the JSP file into a Servlet.
Use powerful
Example URL: The Servlet is compiled and executed.
Suitable for small to large
Scalability Highly scalable https://www.example.com/index.html The Servlet interacts with the database or business logic.
applications
Components of a URL: The response is sent back to the client as an HTML page.
Strong security Protocol → https:// (Secure HTTP)
Security Integrated Windows security
mechanisms Domain Name → www.example.com B. JSP Servers
Path → /index.html (specific file) JSP pages require web servers with JSP support. Popular JSP servers
4. World Wide Web (WWW) and Web Technologies include:
A. Basic Concepts of WWW Conclusion Apache Tomcat (Open-source, widely used).
Invented by Tim Berners-Lee in 1989. HTML provides the foundation for web pages using elements, text, JBoss Application Server.
Uses Hypertext to link documents. links, lists, and tables. WebLogic Server.
Works on HTTP protocol for communication. Dynamic pages use JavaScript, CSS, and databases. GlassFish.
Web servers and clients communicate using HTTP.
B. Web Client and Web Server Microsoft (.NET) and Java (J2EE) offer competing technologies for web 2. JSP Tags
Web Client (Browser) development. JSP supports different types of tags for embedding Java code into
Requests web pages from a server. Understanding the WWW, URL, and HTTP is crucial for web HTML:
Examples: Chrome, Firefox, Edge. application development. Tag Type Syntax Purpose
Web Server Mastering HTML and web technologies is key to building modern and Used to define global settings like
Stores and serves web pages. interactive websites! Directive <%@
importing Java classes (<%@ page
Examples: Apache, Nginx, IIS. Java Server Pages (JSP) – Detailed Theoretical Explanation Tags directive %>
import="java.util.*" %>)
1. JSP (JavaServer Pages) <%!
C. HTTP Protocol and Frame Format JSP is a server-side technology that allows developers to create Declaration Used to declare class-level variables and
Hypertext Transfer Protocol (HTTP) is used for web communication. declaration
dynamic web pages using Java. It extends Servlets by allowing Java Tags methods (<%! int counter = 0; %>)
HTTP Request Format: %>
code to be embedded directly into HTML. Scriptlet <% Java code Used to embed Java code inside HTML
GET /index.html HTTP/1.1 A. JSP Architecture
Host: www.example.com Tags %> (<% int x = 10; %>)
JSP follows a three-tier architecture, which consists of:
HTTP Response Format: <%=
Client Tier: Web browser that requests a JSP page. Expression Evaluates and prints Java expressions
HTTP/1.1 200 OK expression
Middle Tier: JSP engine, which processes JSP requests and generates Tags (<%= x * 5 %>)
Content-Type: text/html %>
dynamic web content.
<html>
28 29 30

Tag Type Syntax Purpose return x * x; B. Using JavaBeans in JSP


Used to include other JSP files } JavaBeans are reusable Java classes used in JSP applications.
Action Tags <jsp:action> %> JavaBean (UserBean.java):
(<jsp:include page="header.jsp"/>)
public class UserBean {
3. Understanding the Layout in JSP <%= square(5) %> <!-- Outputs: 25 --> private String name;
JSP pages have a structured layout, similar to an HTML page, but
include JSP elements: 5. Inserting Java Expressions in JSP public void setName(String name) { this.name = name; }
<%@ page language="java" contentType="text/html"%> Expressions allow dynamic content generation: public String getName() { return name; }
<html> <% }
<head> int a = 10, b = 20; Using Bean in JSP:
<title>JSP Example</title> %> <jsp:useBean id="user" class="UserBean" />
</head> Sum: <%= a + b %> <!-- Outputs: Sum: 30 --> <jsp:setProperty name="user" property="name" value="John"/>
<body> User: <jsp:getProperty name="user" property="name"/>
<h1>Welcome to JSP</h1> 6. Processing User Requests and Generating Dynamic Responses
<% JSP processes user input via the request object 8. Using include and forward Action
String name = "User"; (request.getParameter()). A. <jsp:include> – Including Files
out.println("Hello, " + name); Example: Handling Form Input Includes another JSP file at runtime.
%> <form method="post" action="process.jsp"> <jsp:include page="header.jsp"/>
</body> Enter Name: <input type="text" name="username"> B. <jsp:forward> – Forwarding Requests
</html> <input type="submit" value="Submit"> Redirects the request to another JSP page.
The <%@ page %> directive defines JSP settings. </form> <jsp:forward page="dashboard.jsp"/>
The <% %> scriptlet allows Java code execution. process.jsp
out.println() sends output to the browser. <% 9. Comparing JSP with Other Technologies
String name = request.getParameter("username"); A. JSP vs. CGI
4. Declaring Variables and Methods in JSP %> Feature JSP CGI
A. Declaring Variables Hello, <%= name %>! Faster (compiled into Slower (new process per
request.getParameter("username") fetches form input. Performance
JSP allows variable declaration inside scriptlets or declaration tags: Servlets) request)
<%! int count = 0; %> <!-- Class-level variable --> The value is displayed dynamically. Scalability High Low
<% int localCount = 5; %> <!-- Method-level variable --> Database Uses Perl or Python DB
B. Declaring Methods 7. Inserting Applets and JavaBeans into JSP Uses JDBC
Support modules
Methods can be declared using declaration tags (<%! %>): A. Using Applets in JSP
Applets (small Java programs) can be embedded using <applet>: B. JSP vs. ASP
<%!
public int square(int x) { <applet code="MyApplet.class" width="300" height="200"></applet>

31 32

Feature JSP ASP <%


Language Java VBScript CallableStatement cs = con.prepareCall("{call getUser(?, ?)}");
Platform Cross-platform Windows-based cs.setInt(1, 101);
cs.registerOutParameter(2, Types.VARCHAR);
Performance High (compiles to bytecode) Moderate
cs.execute();
10. Database Connectivity with JSP String name = cs.getString(2);
JSP uses JDBC (Java Database Connectivity) to interact with databases. out.println("User: " + name);
A. Creating an ODBC Data Source Name (DSN) %>
Open ODBC Data Source Administrator.
Select System DSN and click Add. Conclusion
Choose a database (MySQL, Oracle). JSP enhances web applications with dynamic content generation.
Assign a Data Source Name (DSN). It integrates Servlets, JavaBeans, and databases for a powerful
B. Introduction to JDBC backend.
JDBC provides an API to connect and interact with databases. JSP is more efficient than CGI and a strong alternative to ASP.
C. Using PreparedStatement JDBC allows JSP to connect to databases securely using
A PreparedStatement prevents SQL injection. PreparedStatement and CallableStatement.
<%
Mastering JSP enables building enterprise-level web applications!
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/dbname",
"user", "password");

String sql = "SELECT * FROM users WHERE id = ?";


PreparedStatement stmt = con.prepareStatement(sql);
stmt.setInt(1, 101);

ResultSet rs = stmt.executeQuery();
while (rs.next()) {
out.println(rs.getString("username"));
}
%>
D. Using CallableStatement
Used for stored procedures.

You might also like