Unit-1
HTML Tags
Lists
- Ordered List
- Unordered List
- Definition List
Tables
Rowspan: Merging two rows
colspan: Merging two columns
Images
Attributes:
- src: Source file
- alt: Image name
Forms
Attributes:
- action: script to run
- method: GET or POST
- target: Where the result is displayed
Controls:
- Text
- Password
- Checkboxes
- Radio
- Selectboxes
- Submit and Reset buttons
Frames
We can divide the page into multiple section either column wise or row wise. Makes the webpage more intuitive.
CSS (Cascading Style Sheets)
Used to describe how the HTML elements are displayed. It is used to decorate a web page and make it more attractive.
Types:
- Inline
- Internal
- External
Inline: Styling in the same line
Internal: Defining styles in HTML itself
External: Linking external styles to the HTML
Border, Padding and Margin
Border: Border around a HTML element
Padding: Space between text inside element and border of the element
Margin: Space outside the margin to other HTML elements
JavaScript
It’s a scripting language, we use it to make web pages more interactive and run scripts on the client side. Features:
- Light weighted
- Interpreted Based
- Event handling
- Validating User’s input
- Object-Oriented
- Client Side
- In-build functions
Declaring Variables
var: It’s used when we want to redeclare the same variable
let: It’s used when we want to redeclare the same variable but inside a block
const: When variable are constant throughout script we use const
Scope of variables
var is function-scoped, meaning it’s scope is inside a function.
let and const are block-scoped, meaning it’s scope resides inside a block like if block.
Event Handlers
Attribute | Event |
---|---|
onclick | mouse click on object |
ondbclick | on double click |
onmouseover | cursor on the object |
onmousedown | mouse button pressed |
onmouseup | mouse button released |
onmousemove | mouse is moved |
onkeydown | a key is pressed |
onkeypress | key is pressed or held down |
onkeyup | key is released |
Example:
Document Object Model (DOM)
The DOM is a top-down representation of all the elements that make up a web page. It’s the interface through which scripts interact with the web page. The Document Object Model represents the page as a tree structure, with the document as the root object, and each element, attribute, and piece of text as a node. This allows scripts to access and manipulate the content, structure, and style of the web page DOM is an interface for HTML. It defines the logical structure of document and the way document is accessed and manipulated. When an HTML document is loaded into a window, it becomes a document object.
Form Validation
Unit-2
XML
XML stands for extensible mark up language. XML was created to structure, store and transport information. We can create our own tags in XML, its platform independent. It is case sensitive and all elements must have closing tags.
Well formed XML Document:
- Must have a root element
- All elements must have closing tags
- Tags are case sensitive
- Elements must be properly nested
Example:
DTD (Document Type Definition)
It’s purpose is to define structure of an XML document. It defines the structure with the list of defined elements. Using DTD we can specify various element types, attributes and their relationship. Basically DTD is used to specify the set of rules for structuring data in XML files.
Syntax:
CDATA: It stands for character data. It will not be parsed and text inside will not be treated as markup language PCDATA: It stands for parsed character data. Data inside will be parsed and treated as markup language.
Example: .dtd file
Types:
- Internal DTD
- External DTD
Internal DTD
External DTD
XML file
person.dtd File
XML Schema
It is commonly known as XML Schema Definition (XSD). It’s used to describe and validate the structure and content of XML data. XML schema defines elements, attributes and data types. Schema element supports namespaces.
It also defines fixed and default values of elements and attributes and also allows the use of datatypes.
Syntax:
Data Types
- String
- Date
- Numeric
- Boolean
Example .xsd file:
Definition Types
- Simple: Its used only in the context of text
- Complex: This allow you to specify which child element your element can contain and provides structure to XML
- Global: You can define a single type which can used by all other references
Unti-3
CGI vs Servlet
Basis | Servlet | CGI |
---|---|---|
Approach | It is thread based, for every new request new thread is created | It is process based, for every new request new process is created |
Languages used | Written in Java | Written in any language |
Object-Oreinted | It’s object oriented as it’s in java | Not always object-oriented as written in many languages |
Portability | It is portable | Not portable |
Persistance | Remains in memory until explicitly destroyed | Removed from memory after process is completed |
Server Independence | It can use any of the web-server | Limited support |
Data Sharing | Possible | Not possible |
Link | Links directly to the server | Does not link the web-server directly to the server |
Http Server | It can read and set HTTP server | It can neither read nor set HTTP server |
Cost | Construction and destruction of threads is not costly | Construction and destruction of new processes is costly |
Speed | Slower | Faster |
Platform dependency | It can be platform independent | Platform dependent |
Life Cycle of a Servlet
It contains four stages:
- Loading a Servlet
- Initializing a Servlet
- Request Handling
- Destroying a Servlet
Life cycle methods:
- Init()
- service()
- destroy()
Deploying Servlet
- Download and Install the Java Software Developmentkit
- Download a server (Tomcat)
- Configure the server
- Setup deployment environment
- Creating DemoServlet
- Compile Servlet and save the class files in classes folder
- Create a Deployment Descriptor (XML)
- Start Tomcat Server
- Open browser and type http://localhost/MyApp/DemoServlet
Session Tracking
Session simply means a particular interval of time. Session tracking is a way to maintain state of a user. HTTP protocol is stateless, each request is considered as a new request, so we need to maintain the states using session tracking techniques.
Session Tracking Techniques:
- Cookies
- Hidden FormField
- URLRewriting
- HttpSession
Cookies
Cookies are text files stored on the client computer and they are kept to maintain various information tracking purpose
It involves three steps:
- Server script send a set of cookies to the browser in response header
- Browser stores this information on the machine
- For future request the browser send those cookies to the server and server uses the information to identify user
Creating Cookie:
Deleting Cookie:
Get Cookie:
HTTPSession
HttpSession interface provides a way to identify the user across multiple requests. Web container creates a session id to identify the particular user. The servlet container uses this interface to create a session between HTTP client and an HTTP server Get HttpSession Object:
Destroy Session:
Set / Get data in Session:
Connecting to JDBC
Java Database Connectivity is commonly used to establish a connection to a database and execute SQL queries.
- Install JAVA and JDBC
- Install a driver on your machine
- Install your DBMS if needed
- Import Packages (java.sql.*)
- Establish Connection
Unit-4
JSP
JSP stands for Java Server Pages. It is a server side technology which is use for creating web applications. It’s used to create dynamic web content. It contains both HTML tags and JSP tags. In JSP tags are used to insert JAVA code into HTML pages. JSP is first converted into servlet by a JSP container before processing the clients request.
Advantages:
- Easy to maintain
- No recompilation or redevelopment
- Less Coding
- Extended version of servlet
Anatomy of JSP
JSP Processing
Once you have JSP capable Web browser, you need to know following things:
- Where to place the files
- How to access the files from your browser
Elements of JSP
Types:
- Expression
- Scriplets
- Directives
- Declarations
Expression
These are one line java expressions, which are relatively small.
Scriplets / Code Snippets
These are multi line java code, used for large blocks of code.
Variables in Scriplets:
- Request
- Response
- Session
- Out
Directives
We can import packages in directives, it starts with <%@.
Syntax:
Types:
- page
- include
- taglib
page: Used to provide information about page
include: Used include a file in the JSP page
taglib: Used to use custom tags in JSP pages
Declarations
Used for defining functions and variables to be used in the JSP
Syntax;
Example:
JSP Implicit Objects
There are 9 JSP implicit objects. These objects are created by the web container that are available to all JSP pages.
Implicit objects:
- out
- request
- response
- config
- application
- session
- pagecontext
- page
- exception
Session Tracking
Cookies
It’s a small piece of information created by JSP that is stored in client’s machine. They are used to store various kind of information like username and password.
Creating a Cookie:
Reading Cookie:
Unit-5
PHP
PHP stands for Hypertext Preprocessor. It’s a server side scripting language that is embedded in html. PHP scripts are executed on the server. It is used to manage dynamic content, databases and session tracking. It supports many databases like MySQL and oracle.
Uses:
- Performs system functions like creating, reading, writing to files
- Modify data in databases
- Access cookie variables and sessions
- Encrypt Data
Characteristics:
- Simplicity
- Efficient
- Security
- Flexibility
- Familiarity
Declaring Variables
All variables are denoted with leading character $. PHP is loosely typed, we don’t have to declare the data type of a variable
Example:
Data Types
- Integers
- Double
- Boolean
- String
- Arrays
- Objects
Example:
Operators
- Arithmetic
- Assignment
- Increment / Decrement
- Comparison
- Conditional
- Logical
Control Structures
- if-else
- else-if
- switch
- while loop
- for loop
- do-while
if-else:
else-if:
Switch:
While Loop
For Loop
do-while:
Functions
- Creating Function
- Calling Function
Functions with parameters:
Session Tracking
Cookies
Syntax:
Example:
Session
Example:
Connecting to Database
File Handling
Reading file: fread()
Writing file: fwrite()
Appending:
Deleting:
Listing Directories: