OPPORTUNITIES TO LEARN ADVANCE WEB DESIGNING TECHNOLOGIES. Java Server PageS

Similar documents
Server-Side Web Development JSP. Today. Web Servers. Static HTML Directives. Actions Comments Tag Libraries Implicit Objects. Apache.

Introduction to J2EE Web Technologies

SSC - Web development Model-View-Controller for Java web application development

Complete Java Web Development

Agenda. Summary of Previous Session. Application Servers G Session 3 - Main Theme Page-Based Application Servers (Part II)

Web Container Components Servlet JSP Tag Libraries

ACM Crossroads Student Magazine The ACM's First Electronic Publication

Pure server-side Web Applications with Java, JSP. Application Servers: the Essential Tool of Server-Side Programming. Install and Check Tomcat

Java 2 Web Developer Certification Study Guide Natalie Levi

CS506 Web Design and Development Solved Online Quiz No. 01

Building Web Applications, Servlets, JSP and JDBC

2. Follow the installation directions and install the server on ccc

Web Programming: Announcements. Sara Sprenkle August 3, August 3, Assignment 6 due today Project 2 due next Wednesday Review XML

Class Focus: Web Applications that provide Dynamic Content

Glassfish, JAVA EE, Servlets, JSP, EJB

Tutorial: Building a Web Application with Struts

Exam Prep. Sun Certified Web Component Developer (SCWCD) for J2EE Platform

Java Server Pages Tutorial

JSP Java Server Pages

Development. with NetBeans 5.0. A Quick Start in Basic Web and Struts Applications. Geertjan Wielenga

DTS Web Developers Guide

PA165 - Lab session - Web Presentation Layer

Java 2 Web Developer Certification Study Guide Natalie Levi; Philip Heller

Servlets. Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun

Developing XML Solutions with JavaServer Pages Technology

INTRODUCTION TO WEB TECHNOLOGY

7 Web Databases. Access to Web Databases: Servlets, Applets. Java Server Pages PHP, PEAR. Languages: Java, PHP, Python,...

Developing a J2EE Application. Web Auction. Gerald Mo

An introduction to web programming with Java

2.8. Session management

Java Servlet and JSP Programming. Structure and Deployment China Jiliang University

Creating Java EE Applications and Servlets with IntelliJ IDEA

Model-View-Controller. and. Struts 2

Controlling Web Application Behavior

Java 2 Web Developer Certification Study Guide Natalie Levi

Java EE Introduction, Content. Component Architecture: Why and How Java EE: Enterprise Java

Java Server Pages and Java Beans

Ch-03 Web Applications

In this chapter, we lay the foundation for all our further discussions. We start

CrownPeak Java Web Hosting. Version 0.20

Database Applications Recitation 10. Project 3: CMUQFlix CMUQ s Movies Recommendation System

Servlet 3.0. Alexis Moussine-Pouchkine. mercredi 13 avril 2011

Client-server 3-tier N-tier

WIRIS quizzes web services Getting started with PHP and Java

Announcements. Comments on project proposals will go out by in next couple of days...

Web Frameworks and WebWork

Building Web Applications with Servlets and JavaServer Pages

White Paper March 1, Integrating AR System with Single Sign-On (SSO) authentication systems

How To Understand The Architecture Of Java 2Ee, J2Ee, And J2E (Java) In A Wordpress Blog Post

Web Applications. For live Java training, please see training courses at

CSc31800: Internet Programming, CS-CCNY, Spring 2004 Jinzhong Niu May 9, Java Servlets

Web Programming II JSP (Java Server Pages) ASP request processing. The Problem. The Problem. Enterprise Application Development using J2EE

Outline. CS 112 Introduction to Programming. Recap: HTML/CSS/Javascript. Admin. Outline

Services. Custom Tag Libraries. Today. Web Development. Role-Based. Development. Code Reuse. Tag Libraries Custom Tags. Tag Lifecycle.

Usability. Usability

Java Servlet 3.0. Rajiv Mordani Spec Lead

Web Application Programmer's Guide

Web Applications. Originals of Slides and Source Code for Examples:

NetBeans IDE Field Guide

Java Web Programming. Student Workbook

Course Number: IAC-SOFT-WDAD Web Design and Application Development

Outline. Lecture 9: Java Servlet and JSP. Servlet API. HTTP Servlet Basics

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

Web Presentation Layer Architecture

Developing Java Web Applications with Jakarta Struts Framework

CIS 455/555: Internet and Web Systems

CONTROLLING WEB APPLICATION BEHAVIOR WITH

Java and Web. WebWork

Java Server Pages combined with servlets in action. Generals. Java Servlets

In this chapter the concept of Servlets, not the entire Servlet specification, is

CS506- Web Design and Development Solved Subjective From Final term Papers. Final term FALL(Feb 2012) CS506- Web Design and Development

Course Name: Course in JSP Course Code: P5

Hello World Portlet Rendered with JSP for WebSphere Portal Version 4.1

Building a Multi-Threaded Web Server

Web Client-Server Architecture To Support Advanced Text Search

Getting Started with Web Applications

Supplement IV.E: Tutorial for Tomcat. For Introduction to Java Programming By Y. Daniel Liang

CGI An Example. CGI Model (Pieces)

JBoss Portlet Container. User Guide. Release 2.0

Web Applications and Struts 2

An introduction to creating JSF applications in Rational Application Developer Version 8.0

Principles and Techniques of DBMS 5 Servlet

The end. Carl Nettelblad

Web Programming with Java Servlets

Japan Communication India Skill Development Center

Japan Communication India Skill Development Center

How to use JavaMail to send

Java Application Developer Certificate Program Competencies

Title Page. Hosted Payment Page Guide ACI Commerce Gateway

Manual. Programmer's Guide for Java API

If you wanted multiple screens, there was no way for data to be accumulated or stored

}w!"#$%&'()+,-./012345<ya

SESM Tag Library. Configuring a Tag Library APPENDIX

Web Pages. Static Web Pages SHTML

J2EE Web Development. Agenda. Application servers. What is J2EE? Main component types Application Scenarios J2EE APIs and Services.

Java Enterprise Edition The Web Tier

Listeners se es. Filters and wrappers. Request dispatchers. Advanced Servlets and JSP

Japan Communication India Skill Development Center

10. Java Servelet. Introduction

Java Technologies. Lecture X. Valdas Rapševičius. Vilnius University Faculty of Mathematics and Informatics

Transcription:

OPPORTUNITIES TO LEARN ADVANCE WEB DESIGNING TECHNOLOGIES Java Server PageS

2 OBJECTIVES What Is a JSP Page? MVC Architecture The Life Cycle of a JSP Page Execution of a JSP page Creating Static Content Creating Dynamic Content JSP Scripting Elements Using Objects within JSP Pages 2

3 INTRODUCTION TO JSP Java servlets can be used to develop dynamically generated web pages. But it is difficult to maintain. If you want to change any code, you will need to edit and recompile the entire Java Servlet. The Answer to this problem is? Java Server Pages 3

4 STATIC & DYNAMIC CONTENTS Static contents Typically static HTML page Same display for everyone Dynamic contents Contents is dynamically generated based on conditions Conditions could be User identity Time of the day User entered values through forms and selections 4

5 INTRODUCING TO JSP (CONTD.) Java Server Page (JSP) technology provides you with a simple way to build and maintain web pages with dynamically generated content. JSPs allow you to separate the dynamic content from the static content of an HTML page. 5

6 BENEFITS OF JSP Content and display logic are separated. Simplify web application development with JSP, JavaBeans and custom tags. Supports software reuse through the use of components (JavaBeans, Custom tags). Automatic deployment. Recompile automatically when changes are made to JSP pages. Easier to author web pages. Platform-independent. 6

7 MVC ARCHITECTURE What is MVC Architecture? Why MVC Architecture? 7

8 WHAT IS MVC ARCHITECTURE? An architecture which implements the separation of business logic and application data from the presentation data to the user is called MVC Architecture 8

9 ADVANTAGES 1) Multiple views using the same model: 2) Easier support for new types of clients: 3) Clarity of design: 4) Efficient modularity: 5) Ease of growth: 6) Distributable: 9

10 SERVLET OR JSP??? Servlet's strength is controlling and dispatching JSP's strength is displaying In a typically production environment, both servlet and JSP are used in a so-called MVC (Model-View-Controller) pattern Servlet handles controller part JSP handles view part 10

11 REQUEST RESPONSE CYCLE IN JSP 1. The user goes to a web site made using JSP. The user goes to a JSP page (ending with.jsp). The web browser makes the request via the Internet. 2. The JSP request gets sent to the Web server. 3. The Web server recognizes that the file required is special (.jsp), therefore passes the JSP file to the JSP Servlet Engine. 4. If the JSP file has been called the first time, the JSP file is parsed, otherwise go to step 7.

12 REQUEST RESPONSE CYCLE IN JSP 5. The next step is to generate a special Servlet from the JSP file. All the HTML required is converted to println statements. 6. The Servlet source code is compiled into a class. 7. The Servlet is instantiated, calling the init and service methods. 8. HTML from the Servlet output is sent via the Internet. 9. HTML results are displayed on the user's web browser

13 JSP LIFE CYCLE PHASES Translation phase Compile phase Execution phase 13

14 LIFE CYCLE METHODS OF JSP 14

15 JSP ENGINE A JSP page is interpreted by a JSP engine. The JSP engine handles requests from the client to the JSP page and then sends appropriate responses from the JSP page back to the client. The JSP engine processes the JSP tags and scriptlets of your JSP page, and then gets the required content for the page. 15

16 RUNNING A JSP PAGE Making JSPs accessible on the web is a straightforward process. You give your file a.jsp extension and place it in the same directories as your normal HTML pages. 16

17 RUNNING A JSP PAGE (CONTD.) Lets say you want to deploy a JSP page HelloWorld.jsp on a Tomcat server Server. You place the JSP page itself in the default location for HTML pages. Any class files required by this page are placed in the corresponding WEB-INF/classes folder. 17

18 WEB APPLICATION DESIGN 18

19 J D College of Engineering & Management 19 SEPARATE REQUEST PROCESSING FROM PRESENTATION public class OrderServlet { public void doget( ){ if(isordervalid(req)){ saveorder(req); out.println( <html> ); out.println( <body> ); Request Processing public class OrderServlet { public void doget( ){ if(bean.isordervalid(..)){ bean.saveorder(.); forward( conf.jsp ); }} Servlet <html> private void isordervalid(.){ <body> JSP } <body> private void saveorder(.){ </html> } Java Beans } isordervalid SaveOrder Pure Servlet

20 JSP SCRIPTING ELEMENTS There are three JSP Constructs: 1. Scripting Elements JSP 2. Directives Directives 3. Actions Scripting Elements Actions 20

21 JSP SCRIPTING ELEMENTS (CONTD.) 1. Scripting Elements Scripting Elements are used to create Objects, define methods and manage the flow control. There are three types of Scripting Elements: 1a. 1b. 1c. Expressions Scriptlets Declarations 21

J D College of Engineering & Management 22 JSP SCRIPTING ELEMENTS (CONTD.) JSP EXPRESSION 1a. Expressions The first type of scripting element is a JSP expression which is used to insert values directly into the output. An expression does not end with a semi colon. Expressions are used to add dynamic content. It acts a println statement. 22

23 DIRECTIVES Directives are messages to the JSP container in order to affect overall structure of the servlet. Syntax <%@ directive {attr=value}* %> 23

24 DIRECTIVES (CONTD.) Three Types of Directives 1. page: Communicate page dependent attributes and communicate these to the JSP container <%@ page import="java.util.* %> 2. include: Used to include text and/or code at JSP page translation-time <%@ include file="header.html" %> 3. taglib: Indicates a tag library that the JSP container should interpret <%@ taglib uri="mytags" prefix="codecamp" %> 24

25 PAGE DIRECTIVE Give high-level information about the servlet that results from the JSP page. Control which classes are imported <%@ page import="java.util.*" %> What MIME type is generated <%@ page contenttype= image/jpeg" %> How multithreading is handled <%@ page isthreadsafe="true" %> --------Default <%@ page isthreadsafe="false" %> What page handles unexpected errors <%@ page errorpage="errorpage.jsp" %> 25

26 include Directive Is processed when the JSP page is translated into a servlet class Effect of the directive is to insert the text contained in another file-- either static content or another JSP page--in the including JSP page Used to include banner content, copyright, Information, or any chunk of content that you might want to reuse in another page Syntax and Example Syntax - <%@ include file="filename" %> Example - <%@ include file="banner.jsp" %> 26

27 TAGLIB DIRECTIVE The taglib directive declares that the page uses custom tags Syntax <%@taglib uri= tag-lib uri prefix= tagprefix %> uri : This attribute defines the URI that uniquely names the set of custom tags. prefix: This attribute defines the prefix used to distinguish a custom tag instance. 27

28 EXAMPLE TO DISPLAY THE CURRENT DATE Using Servlet import javax.servlet.*; import javax.servlet.http.*; import java.io.*; Import java.util.*; public class MyServlet extends HttpServlet { public void doget(httpservletrequest req,httpservletrespone res) throws ServletException,IOException { res.setcontenttype( text/html ); PrintWriter pw=res.getwriter(); pw.println(new Date()); } } Using JSP <%@page import= java.util.* %> <%=new Date() %> The Servlet And JSP will yield the same output 28

29 IMPLICIT OBJECTS There are a set of objects that are available for use in JSP documents without being declared in the JSP page. The following objects are implicitly created request response out session application pagecontext config page exception HttpServletRequest HttpServletResponse JspWriter HttpSession ServletContext PageContext ServletConfig Current instance of JSP Represents the java.lang.throwable object. 29

30 USAGE OF THE IMPLICIT OBJECTS request One of the most common uses of the request object is to access the request parameters: <% String user=request.getparameter( uname ) %> session The session object is used to hold client information in between client request <% session.setattribute( username,user); %> For retrieving information from the session use: <% Object o=session.getattribute( username ); %> 30

TRANSFERRING CONTROL TO OTHER WEB COMPONENTS <jsp:include> Is processed when a JSP page is executed Allows you to include either a static or dynamic resource in a JSP file static: its content is inserted into the calling JSP file dynamic: the request is sent to the included resource, the included page is executed, and then the result is included in the response from the calling JSP page. Syntax and example Syntax - <jsp:include page="includedpage" /> Example - <jsp:include page="date.jsp"/> 31

J D College of Engineering & Management 32 TRANSFERRING CONTROL TO OTHER WEB COMPONENTS <jsp:forward > This action enables the JSP engine to dispatch, at runtime, the current request to a static resource, servlet, or another JSP. The appearance of this action terminates the execution of the current page. Syntax and example Syntax - <jsp:forward page="includedpage" /> Example - <jsp:forward page="date.jsp"/> The page attribute represents the relative URL of the target forward.

J D College of Engineering & Management 33 TRANSFERRING CONTROL TO OTHER WEB COMPONENTS <jsp:param> This action is used to provide name/value pairs of information by including them as subattributes of the <jsp:forward>,<jsp:include> and <jsp:plugin> actions Syntax <jsp:param name= paramname value= paramvalue /> name attribute refers the name of the attribute being referenced value attribute represents the value of the named parameter.

34 WHAT ARE JAVA BEANS? Java classes that can be easily reused and composed together into an application. Any Java class that follows certain design conventions can be a JavaBeans component. Within a JSP page, you can create and initialize beans and get and set the values of their properties. JavaBeans can contain business logic or database access logic.

35 JAVA BEAN DESIGN CONVENTIONS JavaBeans maintain internal properties A property can be Read/write, read-only, or write-only Simple or indexed Properties should be accessed and set via getxxx and setxxx methods JavaBeans must have a zero-argument contructor.

36 EXAMPLE OF A JAVA BEAN package pack1; public class Employee { private String name; private double sal; public Employee() { name = null; sal = 0.0; } public void setname(string name) { name=this.name; } public void setsal(double sal) { this.sal=sal; } public double calculatehra() { double hra=sal*.20; return hra; } }

37 USE JAVA BEANS FROM A JSP PAGE JSP pages can use JSP elements to create and access the object that conforms to JavaBeans conventions <jsp:usebean id= id" class= package.javabeanclass" scope= request/session/application/page"/> Example: To access the Employee Java Bean created before <jsp:usebean id= emp class= pack1.employee />

38 SETTING PROPERTY TO THE JAVA BEAN Two ways to set a property of a bean Via scriptlet: <% beanname.setpropname(value); %> Via jsp:setproperty: <jsp:setproperty name="beanname property="propname" value="string constant"/> beanname must be the same as that specified for the id attribute in a usebean element. There must be a setpropname method in the bean.

39 SCOPE OF A BEAN COMPONENT Most Visible application Objects accessible from pages that belong to the same application Least Visible session request page Objects accessible from pages belonging to the same session as the one in which they were created. Objects accessible from pages processing the request where they were created Objects accessible only within pages where they were created

THANKS!!! Prof. Kemal Koche M. No. :-9823467431 Email:-kukoche@jdcoem.ac.in 40