Presentation is loading. Please wait.

Presentation is loading. Please wait.

 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.

Similar presentations


Presentation on theme: " Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages."— Presentation transcript:

1  Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages

2  Copyright Wipro Technologies JSP Ver 1.0 Page 2 Talent Transformation Objectives At the end of this session, you will be able to: Distinguish JSP architecture vis-à-vis servlets Define and use the basic JSP Elements Create and use Java Beans Work with Cookies Define Session Tracking and use the same in JSPs

3  Copyright Wipro Technologies JSP Ver 1.0 Page 3 Talent Transformation What is JSP JSP stands for Java Server Pages, a technology invented by Sun to allow the easy creation of server side HTML pages.

4  Copyright Wipro Technologies JSP Ver 1.0 Page 4 Talent Transformation JSP Request Model

5  Copyright Wipro Technologies JSP Ver 1.0 Page 5 Talent Transformation What makes JSP so attractive? High performance Convenient to code and maintain as against servlets Separates presentation from content Powered by Java –Has access to all Java APIs –Has access to all J2EE APIs –Inherent Platform independence

6  Copyright Wipro Technologies JSP Ver 1.0 Page 6 Talent Transformation JSP compared to ASP Similarities –Both provide built in session tracking –Designed to create interactive pages in a Web application –Separate presentation logic from programming logic Differences –JSPs are designed for Platform independence and server independence –Open development process, has come through the JCP (Java Community Process) and hence broader acceptance –JSP enables developers to extend the tags –JSP uses a full fledged language like Java for scripting while ASP uses VBScript or Jscript, which are limited

7  Copyright Wipro Technologies JSP Ver 1.0 Page 7 Talent Transformation The Architecture

8  Copyright Wipro Technologies JSP Ver 1.0 Page 8 Talent Transformation The flow of JSP request

9  Copyright Wipro Technologies JSP Ver 1.0 Page 9 Talent Transformation Elements of JSP The three basic elements of a JSP are: Scripting elements Directives Actions

10  Copyright Wipro Technologies JSP Ver 1.0 Page 10 Talent Transformation Scripting Elements Lets you insert Java code into the servlet that will be generated from the current JSP page There are three forms: -Expressions -Scriptlets -Declarations

11  Copyright Wipro Technologies JSP Ver 1.0 Page 11 Talent Transformation Expressions A JSP expression is used to insert Java values directly into the output. It has the following form:

12  Copyright Wipro Technologies JSP Ver 1.0 Page 12 Talent Transformation Predefined Variables To simplify the expressions, there are a number of predefined variables that you can use The most important ones are: request response session out

13  Copyright Wipro Technologies JSP Ver 1.0 Page 13 Talent Transformation Scriptlets Are defined as any block of valid Java code that resides between tags Code that is defined within a scriptlet can access any variable and any beans that have been declared

14  Copyright Wipro Technologies JSP Ver 1.0 Page 14 Talent Transformation Declaration Used to define methods or fields that get inserted into the main body of the servlet class It has the form: The scope of a declaration is usually a JSP file, but if the JSP file includes other files with the include directive, the scope expands to cover the included files as well

15  Copyright Wipro Technologies JSP Ver 1.0 Page 15 Talent Transformation Directives Affect the overall structure of the servlet class generated from this JSP. format: There are two main types of directives: – page –include

16  Copyright Wipro Technologies JSP Ver 1.0 Page 16 Talent Transformation Page Directives Defines attributes that apply to an entire JSP page Lets you do things like: -Import classes -Handle error messages -Define if the JSP is thread-safe -Define is session object is available -Set the page content type

17  Copyright Wipro Technologies JSP Ver 1.0 Page 17 Talent Transformation The Include Directive  Inserts the contents of another file in the main JSP file, where the directive is located  Useful for including copyright information, scripting language files, or anything you might want to reuse in other applications  The included file can be an HTML file, a JSP file, a text file, or a code file written in the Java programming language

18  Copyright Wipro Technologies JSP Ver 1.0 Page 18 Talent Transformation Actions Control the behavior of the servlet engine You can dynamically insert a file, reuse JavaBeans components Available actions include: -jsp:include -jsp:forward -jsp:useBean

19  Copyright Wipro Technologies JSP Ver 1.0 Page 19 Talent Transformation The jsp:include Action Lets you insert files into the page being generated The syntax looks like this: Unlike the include directive, which inserts the file at the time the JSP page is translated into a servlet, this action inserts the file at the time the page is requested

20  Copyright Wipro Technologies JSP Ver 1.0 Page 20 Talent Transformation The jsp:forward Action Forwards a client request to an HTML file, JSP file, or servlet for processing. Syntax –

21  Copyright Wipro Technologies JSP Ver 1.0 Page 21 Talent Transformation The jsp:useBean Action Lets you load in a JavaBean to be used in the JSP page The simplest syntax for specifying that a bean should be used is: This usually means "instantiate an object of the class specified by class, and bind it to a variable with the name specified by id."

22  Copyright Wipro Technologies JSP Ver 1.0 Page 22 Talent Transformation Converts property names following the bean standards Has two attributes: -name ="beanInstanceName" The name of the Bean instance as declared in a tag -property ="propertyName" The name of the Bean property whose value you want to display

23  Copyright Wipro Technologies JSP Ver 1.0 Page 23 Talent Transformation Sets the value of one or more properties in a JavaBean component Syntax:

24  Copyright Wipro Technologies JSP Ver 1.0 Page 24 Talent Transformation Properties of JSP:setProperty name property value param

25  Copyright Wipro Technologies JSP Ver 1.0 Page 25 Talent Transformation Cookies Allow the web server to store small pieces of data on the client that can be sent back to the server on subsequent page requests Are often used to store user IDs or basic configuration information To read cookies from the browser, use the request.getCookies() function

26  Copyright Wipro Technologies JSP Ver 1.0 Page 26 Talent Transformation Session Management JSP maintains session through the HttpSession object Session information is stored on the server, and a session ID number is stored in a cookie on the client machine Sessions are usually set by server default to expire after 30 minutes of user inactivity

27  Copyright Wipro Technologies JSP Ver 1.0 Page 27 Talent Transformation Summary In this section, you have learnt to: Distinguish JSP architecture vis-à-vis servlets Define and use the basic JSP Elements Create and use Java Beans Work with Cookies Define Session Tracking and use the same in JSPs

28  Copyright Wipro Technologies JSP Ver 1.0 Page 28 Talent Transformation

29  Copyright Wipro Technologies JSP Ver 1.0 Page 29 Talent Transformation

30  Copyright Wipro Technologies JSP Ver 1.0 Page 30 Talent Transformation

31  Copyright Wipro Technologies JSP Ver 1.0 Page 31 Talent Transformation

32  Copyright Wipro Technologies JSP Ver 1.0 Page 32 Talent Transformation

33  Copyright Wipro Technologies JSP Ver 1.0 Page 33 Talent Transformation

34  Copyright Wipro Technologies JSP Ver 1.0 Page 34 Talent Transformation

35  Copyright Wipro Technologies JSP Ver 1.0 Page 35 Talent Transformation

36  Copyright Wipro Technologies JSP Ver 1.0 Page 36 Talent Transformation

37  Copyright Wipro Technologies JSP Ver 1.0 Page 37 Talent Transformation

38  Copyright Wipro Technologies JSP Ver 1.0 Page 38 Talent Transformation

39  Copyright Wipro Technologies JSP Ver 1.0 Page 39 Talent Transformation

40  Copyright Wipro Technologies JSP Ver 1.0 Page 40 Talent Transformation

41  Copyright Wipro Technologies JSP Ver 1.0 Page 41 Talent Transformation

42  Copyright Wipro Technologies JSP Ver 1.0 Page 42 Talent Transformation

43  Copyright Wipro Technologies JSP Ver 1.0 Page 43 Talent Transformation

44  Copyright Wipro Technologies JSP Ver 1.0 Page 44 Talent Transformation

45  Copyright Wipro Technologies JSP Ver 1.0 Page 45 Talent Transformation

46  Copyright Wipro Technologies JSP Ver 1.0 Page 46 Talent Transformation

47  Copyright Wipro Technologies JSP Ver 1.0 Page 47 Talent Transformation

48  Copyright Wipro Technologies JSP Ver 1.0 Page 48 Talent Transformation

49  Copyright Wipro Technologies JSP Ver 1.0 Page 49 Talent Transformation

50  Copyright Wipro Technologies JSP Ver 1.0 Page 50 Talent Transformation

51  Copyright Wipro Technologies JSP Ver 1.0 Page 51 Talent Transformation

52  Copyright Wipro Technologies JSP Ver 1.0 Page 52 Talent Transformation

53  Copyright Wipro Technologies JSP Ver 1.0 Page 53 Talent Transformation

54  Copyright Wipro Technologies JSP Ver 1.0 Page 54 Talent Transformation


Download ppt " Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages."

Similar presentations


Ads by Google