You are on page 1of 24

WHAT IS JSP???

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 THE WEB ARCHITECTURE OF JSP?

JSP MODEL I ARCHITECTURE

JSP MODEL II ARCHITECTURE

HOW MANY STAGES IN JSP LIFE CYCLE

FIVE STAGES OF JSP LIFE CYCLE


1. Page Translation stage

2. Page compilation stage


3. Loading & initialization stage 4. Request handling stage

5. Destroying stage

JSP LIFE CYCLE AS.

WHAT ARE JSP ELEMENTS AN THEIR TYPES????

WHAT ARE JSP ELEMENTS?????


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. 2. 3. 4. 5. 6. 7. 8. 9. Autoflush=true/false Buffer=in KB contentType=info errorPage=page url extends=classname import=package separated by comma info=infotext isELIgnored=true/false isErrorPage=pagenameurl

10. isThreadSafe=true/false 11. language=java 12. pageEncoding=ISO-8859-1 13. session=true/false

WHAT ARE JSP ELEMENTS?????


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

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

1. <%! This is a declaration %> 2. <% this is a scriptlet %> 3. <% = this is an expression %>

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

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


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 ?????????


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.

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=beannameproperty=propertyname>

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=beannameproperty=propertyname>

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>

NOW UNDERSTAND THIS USING EXAMPLE

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

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>

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>

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; }

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.eq uals("123")) { result=true; } else { result=false; } return result;

} }

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>

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

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.

You might also like