Jsp presentation

24
JSP is a java based technology used to simplify the development of dynamic web pages. JSP is used to separate dynamic content of web page from its content with the help of HTML and JSP tags. Current version is 2.1. WHAT IS JSP???

description

This tutorial created by sher singh for Advance java beginners with it you can lear JSP in 5 minutes only

Transcript of Jsp presentation

Page 1: Jsp presentation

JSP is a java based technology used to simplify the development of dynamic web pages. JSP is used to separate dynamic content of web page from its content with the help of HTML and JSP tags. Current version is 2.1.

WHAT IS JSP???

Page 2: Jsp presentation

WHAT THE WEB ARCHITECTURE OF JSP?

Page 3: Jsp presentation

JSP MODEL I ARCHITECTURE

Page 4: Jsp presentation

JSP MODEL II ARCHITECTURE

Page 5: Jsp presentation

HOW MANY STAGES IN JSP LIFE CYCLE

Page 6: Jsp presentation

1. Page Translation stage

2. Page compilation stage

3. Loading & initialization stage

4. Request handling stage

5. Destroying stage

FIVE STAGES OF JSP LIFE CYCLE

Page 7: Jsp presentation

JSP LIFE CYCLE AS……….

Page 8: Jsp presentation

WHAT ARE JSP ELEMENTS AN THEIR TYPES????

Page 9: Jsp presentation

JSP page consist of elements and templates data .These elements are described in different elements type are:-

Directives:- JSP directives provides the page resources and their properties. Some are as:-

1. Page directive:-Used to provide page specific properties

Eg:<%@page contentType=”text/html” language=”java” %>

Attributes are:-

1. Autoflush=”true/false”

2. Buffer=”in KB”

3. contentType=”info”

4. errorPage=”page url”

5. extends=”classname”

6. import=”package separated by comma”

7. info=”infotext”

8. isELIgnored=”true/false”

9. isErrorPage=”pagenameurl”

10. isThreadSafe=”true/false”

11. language=”java”

12. pageEncoding=”ISO-8859-1”

13. session=”true/false”

WHAT ARE JSP ELEMENTS?????

Page 10: Jsp presentation

2. Include Directives:-The include directives tells the container to add the defined resource content inline to the JSP page during the translation time .This tag used to make reusability.

Eg :-

<%@ include file=”header.html” %>

3. Taglib Directives:-Taglib tag is used to include external tag library in your web page.

Attributes are:-

1.Uri=”url of taglibrary”

2.tagDir=”tag library directory”

3.prefix=”like object for library”

WHAT ARE JSP ELEMENTS?????

Page 11: Jsp presentation

HOW MANY SCRIPTING ELEMENTS USED IN JSP?????

• 1. <%! This is a declaration %>

• 2. <% this is a scriptlet %>

• 3. <% = this is an expression %>

Page 12: Jsp presentation

NOW I AM DESCRIBING ACTION ELEMENTS IN JSP ?????????

Page 13: Jsp presentation

Action elements are certain directives that are given to the container perform certain task during the

execution of a JSP page.

DESCRIBING ACTION ELEMENTS IN JSP ?????????

Page 14: Jsp presentation

DESCRIBING ACTION ELEMENTS IN JSP ?????????

1. <JSP:useBean>:-

The useBean tag is used to create instance for specified java bean for JSP page.

Attributes of this tag:-

Id => what the object name you want to specifiy for this bean.

Scope => whats the scope of bean object page,request,session or application.

Class => case sensitive name of bean class

beanName => a valid bean name no include the bean classname

type => optional attribute java class has been defined.

Page 15: Jsp presentation

DESCRIBING ACTION ELEMENTS IN JSP ?????????

• 1. <JSP:getProperty> :-

• this action used to access the defines property to bean object.But it is important to declare bean object using useBean tag.

• Attributes are:-

• 1. name :- The name of object where to retrieve object properties.

• 2. property: - Name of property to get.

• Eg:-

• <jsp:getProperty name=”beanname”property=”propertyname”>

Page 16: Jsp presentation

DESCRIBING ACTION ELEMENTS IN JSP ?????????

• 1. <JSP:getProperty> :-

this action used to access the defines property to bean object.But it is important to declare bean object using useBean tag.

Attributes are:-

1. name :- The name of object where to retrieve object properties.

2. property: - Name of property to get.

Eg:-

<jsp:getProperty name=”beanname”property=”propertyname”>

Page 17: Jsp presentation

DESCRIBING ACTION ELEMENTS IN JSP ?????????

. <JSP:setProperty> :-

This action element is used to set the property of bean object specified by usebean tag.

Attributes are:-

1.Name :- name of bean which have to specify value

2.Property:-

name of property value to be set we can also use * to specify all the property of bean.but in this case you have to specify the name of components as bean property.

3.Param:- The name of the request parameter whose value you want to give to a bean property.this name basically come from web form.

4.Value:- the value to be assign to this property.

Eg:-

<jsp:setProperty name=”beanname” property=”propertyname” value=”tobeset” >

=”propertyname”>

Page 18: Jsp presentation

We are creating a login screen with java bean which check the username and password and return the

result according to input

NOW UNDERSTAND THIS USING EXAMPLE

Page 19: Jsp presentation

INDEX.JSP<%-- DOCUMENT : INDEX CREATED ON : APR 2, 2012, 12:23:12 PM AUTHOR : BARDHAN--%> <%@PAGE CONTENTTYPE="TEXT/HTML" PAGEENCODING="UTF-8"%><!DOCTYPE HTML><HTML> <HEAD> <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="TEXT/HTML; CHARSET=UTF-8"> <TITLE>JSP PAGE</TITLE> </HEAD> <BODY> <FORM ACTION="CHECK.JSP" METHOD="POST"> ENTER NAME <INPUT TYPE="TEXT" NAME="NAME" /><BR> ENTER PASSWORD <INPUT TYPE="PASSWORD" NAME="PASSWORD" /> <BR/> <INPUT TYPE="SUBMIT" VALUE="LOGIN" /> <INPUT TYPE="RESET" VALUE="RESET" /> </FORM> </BODY></HTML>

Page 20: Jsp presentation

CHECK.JSP PAGE:-<%-- DOCUMENT : CHECK CREATED ON : APR 2, 2012, 12:29:55 PM AUTHOR : BARDHAN--%> <%@PAGE CONTENTTYPE="TEXT/HTML" PAGEENCODING="UTF-8"%><!DOCTYPE HTML><HTML> <HEAD> <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="TEXT/HTML; CHARSET=UTF-8"> <TITLE>JSP PAGE</TITLE> </HEAD> <BODY> <JSP:USEBEAN ID="LOGIN" CLASS="BEANS.LOGIN" SCOPE="PAGE"> <JSP:SETPROPERTY NAME="LOGIN" PROPERTY="*" /> </JSP:USEBEAN> YOUR NAME:<JSP:GETPROPERTY NAME="LOGIN" PROPERTY="NAME" /> <BR> YOUR PASSWORD IS:<JSP:GETPROPERTY NAME="LOGIN" PROPERTY="PASSWORD" /> <%BOOLEAN BA=LOGIN.GETRESULT(); IF(BA) { RESPONSE.SENDREDIRECT("WELCOME.JSP"); } ELSE{ OUT.PRINTLN("THIS IS NOT RIGHT USERNAME OR PASSWORD"); } %> </BODY></HTML>

Page 21: Jsp presentation

• public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public boolean getResult() { if(this.name.equals("sanju")&&password.equals("123")) { result=true; } else { result=false; } return result; } }

• Bean.login bean:-/* * To change this template, choose Tools | Templates * and open the template in the editor. */package beans; /** * * @author BARDHAN */public class login { private String name; private String password; private boolean result; public String getName() { return name; }

Page 22: Jsp presentation

DESCRIBING ACTION ELEMENTS IN JSP ?????????

4. .<JSP:param>:-

This action element is used to pass the parameter to other action elements. For example

<jsp:forward page=”hello.jsp”>

<jsp:param name=”id” value=”12” />

</jsp:forward>

Page 23: Jsp presentation

DESCRIBING ACTION ELEMENTS IN JSP ?????????

• 5.<jsp:include> :-

• This action element is used to include any jsp file in your web page.

• <jsp:include page=”header.jsp” flush=”true|false” />

• 6.<jsp:forward> :-

• Used to forward request control to next page .For example

• <jsp:forward page=”next.jsp” ></jsp:forward>

• 7.<jsp:expression>:- work like expression script

• 8.<jsp:scriptlet> :- work like as script element

• 9.<jsp:declaration> :-work as declaration element

Page 24: Jsp presentation

DESCRIBING THE JSP IMPLICIT OBJECTS…………………….

JSP Implicit objects are described as follows

1. Application :- Used as Servlet Context object in servlets

2. Config:- Used as ServletConfig object in servlets

3. Out :- JSPWriter object to print any thing on jsp page

4. Page:- work like as Object class object

5. pageContext:- PageConext for JSP page

6. request: work like as ServletRequest object

7. response:- work like as ServletResponse Object in Servlets

8. session :- like as httpSession.