Professional Documents
Culture Documents
Ardent J2EE
Ardent J2EE
Presented By
Ardent Computech Pvt Ltd
HTML OVERVIEW
Introduction to HTML
The Problem
The Solution:
2. Semantic Tags
Presentation Tags 4. Logical Tags
Links & Graphics – Emphasized Tag
List – Strong Tag
Dividers – Code Tag
Backgrounds and Colors
Special Characters
Layout Tag
Layout tags define the layout of the WEB Page and define what text
goes where and is displayed where.
BASIC Tags:
<HTML></HTML> Defines Start and end of Web page
<HEAD></HEAD> Defines the Header section of the Web Page
<TITLE></TITLE> Defines the Title of the web page displayed on the title bar
STRUCTURAL Tags:
<H?></H?> Heading tags. ‘?’ Ranges from 1 to 6, defines heading
<PRE></PRE>Preformatted Text
Semantic Tag
1. Presentation Tags
2. Links & Graphics
3. Lists
4. Dividers
5. Backgrounds and Colors
6. Special Characters
Semantic Tag: Presentation Tags
Bold <B>Text</B> Superscript <SUP></SUP>
FONT SETTINGS:
<FONT
SIZE=“12 / + / - ” Attribute set
COLOR=“#FFOO00”
FACE=“Times” >
</FONT>
Semantic Tag: Links and Graphics
Anchor: <A>
An anchor can be used to create a link to another
document (with the href attribute) or to create a
bookmark inside a document (with the name
attribute).
Syntax:
<A HREF=“URL”>Display Text</A>
Links and Graphics (Contd..)
Image:
<IMG SRC=“URL” ALT=“Alternate Text”>
Example:
<IMG SRC=“\images\wipro.jpg”
ALT=“Alternate Text”>
Semantic Tag: List
Semantic tags provide the Author with feature of
displaying text in
hierarchical or tree structure format.
Output:
A. Country
1. India
List: Un-Ordered List
An unordered list is a list of items. The list items are marked with
bullets.
Example:
<UL TYPE=“Square / Circle / Disc”>
<LI>Country</LI>
<UL TYPE=“”>
<LI>India</LI>
</UL>
</UL>
Semantic Tag: Dividers
Paragraph:
<p align=“Left/center/right/justify”>Text</p>
LineBreak:
Horizontal Rule:
Example:
< <
> >
& &
“ "
Registered Trade mark ® or ®
Copyright © or ©
Non-Breaking space
Application Tags
1. Table
2. Form
3. Frames
Application Tags: Tables
Tags Purpose
EXAMPLE:
2. COLSPAN
Used to merge cells in Columns
<TD COLSPAN=“2”> two cells in consecutive
rows are merged
Application tags: Forms
Mode of accepting input from user
Container: Form
<FORM NAME=“” ACTION=“” METHOD=“”></FORM>
There are other tags like TEXTAREA and SELECT for other purposes.
Forms: Input tags
Input tag is a single tag option for gathering information
Input tag contains all of the other options for acquiring information,
including simple text fields, password fields, radio buttons, check
boxes, and the buttons to submit and reset the form.
<INPUT TYPE = “ * ” > * can take the following values:
Text TextField
Checkbox Checkbox
EXAMPLE:
</TEXTAREA>
select
Select is used to display list box.
<SELECT NAME=“” MULTIPLE>
<OPTION VALUE=“taken value”>Display text</OPTION>
</SELECT>
EXAMPLE:
<select name="locations" align="center">
<option value="EC1">EC1</option>
<option value="EC2">EC2</option>
<option value="EC3">EC3</option>
<option value="EC4">EC4</option>
</select>
Application Tags: Frames
<FRAMESET COLS="25%,*">
<FRAME SRC=“left.htm“ NAME=“left”>
<FRAME SRC=“right.htm“
NAME=“right”>
</FRAMESET>
Frames (Contd..)
<FRAMESET COLS="25%,*">
<FRAME SRC=“top.htm“
NAME=“header”>
<FRAME SRC=“body.htm“
NAME=“body”>
</FRAMESET>
Nested Frames
<FRAMESET ROWS="25%,75%">
<FRAME SRC="top.htm" NAME="left"/>
<FRAMESET COLS="25%,75%">
<FRAME SRC="left.htm"
NAME="left"/>
<FRAME SRC="right.htm"
NAME="right"/>
</FRAMESET>
</FRAMESET>
SERVLET
Introduction to Servlet
31
Introduction to Servlet: Static Web Site
HTTP Server
HTML HTTP
<HTML>
Aruba
Bermuda
Bahamas
</HTML>
Source: http://www.myvacation.com/ListDest.htm
32
Dynamic Page Generation Using CGI
ODBC / Native
HTTP Server
HTML HTTP CGI
Application
<HTML>
Aruba
Bermuda
Bahamas
</HTML>
Source: http://www.myvacation.com/cgi/ListDest.exe
33
Dynamic Page Generation Using
Servlets
HTTP Server
Servlet
JDBC
HTML HTTP
Container
<HTML>
Aruba
Bermuda
Bahamas
</HTML>
Source: http://www.myvacation.com/servlet/ListDest.htm
34
What is a Servlet?
Server side Java program that extends the functionality
of a Web Server
Used to dynamically generate HTML documents
Comparable to:
CGI
Netscape NSAPI
Microsoft ISAPI
Apache Modules
35
Servlet: Benefits
Written in pure Java
Platform independent
Can take advantage of JDBC, EJB, JMS, JavaMail, JavaIDL, RMI, ...
Server independent
Scalability
Don’t start new process for each request
Can run in same server process as HTTP server
Multi-threaded
36
Servlet: Advantages over CGI
A Servlet does not run in a seperate process
37
Servlet Life Cycle
Servlets Container
Thread
HTTP Server init( )
doGet( )
Thread
Servlet
Thread
38
Servlet Life Cycle (Contd.).
Servlets Container
Thread
HTTP Server init( )
doGet( )
Servlet
Thread
39
Servlet Life Cycle (Contd.).
Servlets Container
Servlet
Thread
40
Servlet Life Cycle (Contd.).
Servlets Container
Servlet
41
Servlet Life Cycle (Contd.).
Servlets Container
HTTP Server
42
Class Hierarchy
Uses of HTTP Servlets
Processing and/or storing data submitted by an HTML
form
45
The init() Method
public void init(ServletConfig) throws ServletException
46
The service() Method
public void Service(ServletRequest,
ServletResponse) throws
ServletException, IOException
47
The destroy() Method
public void destroy()
48
Handling HTTP GET requests
Override the doGet method.
49
Reading Servlet Parameters
The ServletRequest class includes methods that allow
you to read the names and values of parameters that
are included in a client request.
Methods used are
getParameterNames()
getParameter(String pname)
getParameterValues(String pname)
50
The servlet Interface
A servlet is Java class that implements the
javax.servlet.Servlet interface
51
ServletConfig Interface
Is implemented by Servlet container in order to pass
configuration information
52
ServletContext Interface
Gives servlets access to information about their
environment
Methods:
getServerInfo()
getAttribute(String name)
getAttributeNames()
setAttribute(String name, Object obj)
log(String)
53
Servlet Chaining: RequestDispatcher
Interface
In order to FORWARD or INCLUDE a request from one
servlet to another Servlet/JSP the RequestDispatcher
interface provides two methods.
1. RequestDispatcher.forward(request,response)
2. RequestDispatcher.include(request,response)
54
Servlet Chaining:
forward(request,response)
ServletContext ctx=getServletContext();
RequestDispatcher
dis=ctx.getRequestDispatcher(“/servlet/AnotherServlet”);
dis.forward(request,response);
55
Servlet Chaining: forward (request ,
response);
Client Request Request passing
Response Generation
56
Servlet Chaining: include(request,
response)
ServletContext ctx=getServletContext();
RequestDispatcher
dis=ctx.getRequestDispatcher(“/servlet/AnotherServlet
”);
dis.include(request,response);
57
Servlet Chaining: include (request ,
response);
58
Servlet Chaining: sendRedirect(url);
WEB CONTAINER
REQUE
ST ST
UE
REQ Http Servlet 1
RESPONSE
REQ
UE
ST
RESP
ONSE
Http Servlet 2
RESPONSE
The Cookie Class
Cookie is a small amount of information sent by the server to the web
browser, saved by the web browser and later send back to the server. A
cookies value can uniquely identify a client, so cookies are commonly
used for session management.
A cookie has a name, a single value and an optional attribute such as a
comment, a maximum age etc.
The servlet sends cookies to the browser by using the
HttpServletResponse.addCookie(javax.servlet.http.Cookie) method, which
adds fields to HTTP response headers to send cookies to the browser,
one at a time.
The browser is expected to support 20 cookies for each Web server,
300 cookies total, and may limit cookie size to 4 KB each.
SESSION TRACKING
What is Session Tracking
HTTP is a “stateless” protocol: each time a client
retrieves a Web page, it opens a separate connection
to the Web server, and the server does not
automatically maintain contextual information about
a client.
Session tracking is a mechanism that servlet use to
maintain state about a series of request from the same
user (i.e. requests originating from the same browser)
across some period of time.
Session Tracking API
Sessions are represented by an HttpSession object
WebApplicationName
_jspservice():
The container calls this method for each request, passing it the request
and response object.
jspDestroy() :
The container calls this when it decides and take the instance out of
service. It is the last method called in the servlet instance.
Various JSP Contents
HTML code: for user interface lay out
JSP tags: declarations, actions, directives,
expressions, scriplets
JSP implicit objects: a request object, response
object, session object, config object
Javabeans: for logic that can be taken care of at the
JSP level.
JSP Tags
JSP Comment
Developer comment that is not sent to the client
Example:
<%-- Start of JSP --%>
JSP Expression
Expression that is evaluated and sent to the client each
time the page is requested
Example:
<%= Java Value %>
<%= Java Expression %>
JSP Tags (Contd..)
JSP Scriptlet
Statement or statements that are executed each time the
page is requested
Example:
<% Java Statement %>
JSP Declaration
Field or method that becomes part of class definition
when page is translated into a servlet
Examples:
<%! Field Definition %>
<%! Method Definition %>
JSP Tags (Contd..)
JSP Directive
Directives are JSP elements that provide global information
about an entire JSP page. Declarative do not produce any
visible output when the page is requested, but change the way
the jsp engine process the request.
Example:
<%@ directive att="val" %>
<%@ page language=“java”%>
JSP Action
Action that takes place when the page is requested
Example:
<jsp:action_name>...</jsp:action_name>
JSP Tags (Contd..)
Some commonly used tag actions types are:
<jsp:useBean>
<jsp:setProperty>
<jsp:getProperty>
<jsp:include>
<jsp:forward>
Predefined Variables
request, the HttpServletRequest.
response, the HttpServletResponse.
session, the HttpSession associated with the
request
out, this is a PrintWriter used to send output to the
client.
Exception, exception represents the uncaught
Throwable that resulted from a call to the error page.
The errorPage and isErrorPage attribute
The errorPage attribute specifies a JSP page that
should process any exceptions thrown but not
caught in the current page. It is used as follows: