Introduction to JavaServer Pages. 2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses.

Slides:



Advertisements
Similar presentations
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Advertisements

Java Script Session1 INTRODUCTION.
Java Server Pages (JSP)
JSP1 Java Server Pages (JSP) Introducing JavaServer Pages TM (JSP TM ) JSP scripting elements.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
DT211/3 Internet Application Development
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
DT228/3 Web Development JSP: Directives and Scripting elements.
Java Server Pages B.Ramamurthy. Java Server Pages Servlets are pure Java programs. They introduce dynamism into web pages by using programmatic content.
Java Server Pages Russell Beale. What are Java Server Pages? Separates content from presentation Good to use when lots of HTML to be presented to user,
Comp2513 Java Server Pages Daniel L. Silver, Ph.D.
Three types of scripting elements: 1.Expressions 2.Scriptlets 3.Declarations Scripting elements.
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 37 - JavaServer Pages (JSP): Bonus for Java Developers Outline 37.1 Introduction 37.2 JavaServer.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
Netbeans – jsp.zip Introduction to JSP Netbeans – jsp.zip.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
JSP Java Server Pages Softsmith Infotech.
Introduction to Java Server Pages (JSPs) Robert Thornton.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
 Embeds Java code  In HTML tags  When used well  Simple way to generate dynamic web-pages  When misused (complex embedded Java)  Terribly messy.
JSP Most of the web developers deploying web applications using servlets mixes the presentation logic and business logic. Separation of business logic.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Stanisław Osiński, 2002JSP – A technology for serving dynamic web content Java Server Pages™ A technology for serving dynamic web content Stanisław Osiński,
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Slides © Marty Hall, book © Sun Microsystems Press 1 JSP Scripting Elements Core Servlets & JSP book:
Chapter 7 Being a JSP. JSP introduction JSP is a solution for two issues  Servlet is difficult for HTML designers since they may not know Java  Formatting.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
CSC 2720 Building Web Applications JavaServer Pages (JSP) The Basics.
Web App GUI: JSP Basics & Forms 3680 Enterprise Programming.
Jsp (Java Server Page) Is a server side program.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Java Server Pages An introduction to JSP. Containers and Components Several clients – one system.
Chapter 11 Invoking Java Code with JSP Scripting Elements.
JSP. Types of JSP Scripting Elements Expressions of the form, which are evaluated and inserted into the servlet's output. Scriptlets of the form, which.
OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
Core basic Java web server technologies. Tools Eclipse IDE for Java EE Developers (Netbeans also works) nloads/packages/eclipse-
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
CSI 3125, Preliminaries, page 1 JSP (Java Server Pages)
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Servers- Apache Tomcat Server Server-side scripts- Java Server Pages.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
JAVA SERVER PAGES -by Rubeena Memon Deepti Jain Jaya Thakar Jisha Vettuventra.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Java Server Pages. 2 Servlets The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
JSP Java Server Pages. Hello, !
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
Java Server Pages (JSP)
Java Server Pages.
Java Server Pages By: Tejashri Udavant..
Java Servlets.
Scripted Page Web App Development (Java Server Pages)
Invoking Java Code from JSP
Java Server Pages B.Ramamurthy.
Introduction to JSP Dept. of B.Voc Software Development and System Administration St. Joseph’s College(Autonomous) Trichy-02 By Dr. J. Ronald Martin Introduction.
Scripted Page Web Application Development (Java Server Pages)
Presentation transcript:

Introduction to JavaServer Pages

2 JSP and Servlet Limitations of servlet  It’s inaccessible to non-programmers JSP is a complement to servlet  focuses on presentation  JSP enhances the design capability of servlet  JSP pages can be written with any text editor, including HTML editor  JSP is a server side technology

3 JSP Pages JSP page file ends with “.jsp” by default JSP like HTML files JSP page is HTML and JSP scripting JSP page is compiled to servlet class

4 JSP Compilation and Execution JSP Page Compile JSP Servlet Instance in Memory init() service() First request after creation or modification Subsequent Requests (can be from different users and sessions) JSP Servlet Automatic Compilation

5 Servlet and JSP ServletJSP Developmentjava classes (.java)scripting file (.jsp) Deployment Manually compiled; Specifically mapped Directly mapped: copy JSP files to intended directories ExecutionNo need of source files Automatic compilation; automatic reloaded; source files (.jsp) are necessary

6 JSP Elements Scripting elements  Scriptlet Regular Java code  Expression Shortcut for output  Declaration Declaring variables and methods at the class level Directive JSP action Comments ( )

7 Scriptlets Wraps regular Java statements which are usually written within a method <% … (Java statements) // may include comments, variable declaration and assignment, loops, conditional statements, object initialization, method call, etc… %> Using the implicit object “out” as the standard output out.println( … ) or out.print( … ) See example “scriptlet-example.jsp”

8 Expression A shortcut to print out a value or an expression  Expression can be a variable, formula, object property, string concatenation, method with return value, or anything that returns a value

9 JSP Output Practices Ways to treat static HTML content  Regular/block output (servlet way) Uses “out.println()” or “out.print()” method to generate all content, including static content  “Spaghetti”/mixed output (scripting way) Uses JSP scriptlets or expressions for dynamic content only Mixes scripting elements and static content

10 Regular Output Using “out.print()” or “out.println()” method to generate HTML as a block, even the whole page – Servlet way

11 Spaghetti Output Expression elements are often used where dynamic content is needed Use regular HTML for static content; don’t include them in JSP scripting elements How mixed should it be?  Depends on your own style  Coding should be most convenient and clear  Depends on development requirement

12 Declarations Declaration element is used to define member variables and methods  Variables not defined in declaration element are local / method level variables  Methods can only be defined in the declaration element Like regular class variables and methods, the location where you define these variables and methods is not important

13 JSP Page Directive Directives affects the overall structure of the servlet generated Use page directive to import classes  This is equivalent to the “import” statement in regular Java classes

14 JSP Include Directive How to reuse code? Use include directive to include source code from another file  Inclusion happens at the compilation time  What is included is the source, not generated result  Often used to include method definitions

15 JSP Include Action Use “jsp:include” action to dynamically include content from other files  The statement is placed where the actual content will be inserted “page” points to a local text file (.html,.htm,.jsp,.txt)  Relative path  Absolute path Note: absolute path starts from the current application context

16 Include Action Usage “jsp:include” is often used to include the contents that are consistent on many pages, e.g., menus, titles, page headers, footnotes, …   See example “ssi.jsp” and “WEB-INF/menu.jsp” Or, it is often used to include contents that are different (dynamic inclusion)    See example “home.jsp” and “WEB-INF/course.htm” Or a hybrid model (templating)

17 Include Action and Directive Comparison Include ActionInclude Directive When does inclusion occur? At request/run timeAt compilation time What’s included? Final output of the included page Source code/content Main page maintenance Updates of the included page is automatically reflected Updates of the included page is NOT automatically reflected

18 Redirection, Refreshing and Forwarding Redirection  response.sendRedirect() Refreshing  response.setHeader(“Refresh”, “10; url=…”) Forwarding  The “page” attribute follows the same rule as that of  Forwarding does not invoke network traffic  The destination URL is hidden; original requested URL does not change in browser address bar after forwarding Compare redirecting and forwarding

19 Request Processing Using implicit object “request” Processing HTTP request headers  The same way as servlet Reading URL parameter  Parameter processing is the same way as servlet, using request.getParameter(“…”), request.getPameterValues(“…”)

20 Form Processing with JSP The same way as servlet request.getParameter(“…”) request.getParameterValues(“…”)  Note: the action attribute of the form should be a JSP file that processes data …

21 Database Processing with JSP The same way as servlet  Don’t forget the directive  See the example “product.jsp”

22 JSP Implicit Objects Summary Some system objects are initialize automatically ready to use in the JSP environment  out: standard output object  request: represents request information and behavior  response: represents response information and behavior  [session]: represents a typical time period of communication between a client and a server  [application]: represents context of a web application