Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.

Slides:



Advertisements
Similar presentations
Servlets & JSPs - Sharad Ballepu.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Servlets and Java Server Pages.
Servlets, JSP and JavaBeans Joshua Scotton.  Getting Started  Servlets  JSP  JavaBeans  MVC  Conclusion.
1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
Java Server Pages (JSP)
Java Servlets Java Server Pages (JSP)
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Servlets and a little bit of Web Services Russell Beale.
An introduction to Java Servlet Programming
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
JSP Java Server Pages Reference:
Servlets CS-328 Dick Steflik. What is a servlet A Java application run on a thread of the webserver in response to an HTTP GET or POST request. The servlet.
Java Server Pages B.Ramamurthy. Java Server Pages Servlets are pure Java programs. They introduce dynamism into web pages by using programmatic content.
Servlets Compiled by Dr. Billy B. L. Lim. Servlets Servlets are Java programs which are invoked to service client requests on a Web server. Servlets extend.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
Michael Brockway Application Integration Servlets l Introduction & Overview l HTTP Servlets l HTTP get Requests l HTTP post Requests l Multi-tier Applications.
SE-2840 Dr. Mark L. Hornick1 Java Servlet-based web apps Servlet Architecture.
Chapter 10 Servlets and Java Server Pages. A servlet is a Java class designed to be run in the context of a special servlet container An instance of the.
Java Servlets. What Are Servlets? Basically, a java program that runs on the server Basically, a java program that runs on the server Creates dynamic.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Introduction to servlet programming Pertemuan 6 Matakuliah: Web Programming Tahun: 2009.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Chapter 11 © 2005 by Addison Wesley Longman, Inc Overview of Servlets - A servlet is a compiled Java class - Servlets are executed on the server.
1 Chapter 2 The Web Tier  Web Applications and Web ContainersWeb Applications and Web Containers  Dynamic Content CreationDynamic Content Creation 
Objectives Java Servlet Web Components
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
CSC 2720 Building Web Applications
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
Java Servlets & Java Server Pages Lecture July 2013.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
L.MARIA MICHAEL VISUWASAM UNIT-4
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
Servlets.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
Java Servlets Java Server Pages (JSP)
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Chapter 4 Request and Response. Servlets are controlled by the container.
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.
1 Lecture 8 George Koutsogiannakis/Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
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 Servlets References: Karen Anewalt, Mary Washington College.
Introduction to Servlets
Servlets.
Servlets.
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
Java Servlets.
MSIS 655 Advanced Business Applications Programming
Chapter 26 Servlets.
Java Server Pages B.Ramamurthy.
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
Objectives In this lesson you will learn about: Need for servlets
COP 4610L: Applications in the Enterprise Spring 2005
J2EE Lecture 1:Servlet and JSP
Java Chapter 7 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

Java Server Pages B.Ramamurthy

Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP fundamentals JSP Examples with Netbeans Finish the semantic web topic

Java Server Pages Servlets are pure Java programs. They introduce dynamism into web pages by using programmatic content. JSP technology is an extension/wrapper over the Java servlet technology. JSP are text based documents. We will focus only on JSP since it subsumes the servlet technology. Two major components of JSP: Static content: provided by HTML or XML Dynamic content: generated by JSP tags and scriplets written in Java language to encapsulate the application logic and XHTML.

JSP compilation into Servlets Web Browser Web Server J2EE Web Container Java Servlets JSP translation Initial request Subseq request

8/20/2015B.Ramamurthy5 Servlets Client-server model: Client requests something of a server and the server performs action(s) and responds to the client. This request-response model is the highest level of networking in Java. A servlet extends the functionality of a server. javax.servlet and javax.servlet.http package provide the classes and interfaces to define servlets.

8/20/2015B.Ramamurthy6 What are servlets? Servlets are server side components/programs that are primarily designed to use with HTTP protocol. ~ provide secure access to a Website and to interact with databases on behalf of a client. ~ dynamically create HTML documents to be displayed by the browser. ~ can maintain unique session information for each client.

8/20/2015B.Ramamurthy7 Support for servlets Servlets are to servers what applets are to a client (web browser). Servlets are normally executed of a web server. Many web servers support servlets: Glassfish, Apache Tomcat, IIS.

8/20/2015B.Ramamurthy8 Servlet API It is good programming practice to start the design/definition with an interface. Conversely interfaces are good starting point to study an API. Servlet interface: void init (ServletConfig config) ServletConfig getServletConfig() void service (ServletRequest req, ServletResponse res) String getServletInfo() void destroy()

8/20/2015B.Ramamurthy9 Servlet API Servlet interface is implemented by two abstract classes GenericServlet and HTTPServlet. HTTPServlet is for interfacing with HTTP protocol and we will look at only this in our discussion today.

8/20/2015B.Ramamurthy10 HTTPServlet Two most common HTTP requests are GET and POST. GET request gets information from the server. For example: retrieve an image or document. POST requests are to send to the server the information from a HTML form which a client enters. For example: request to search internet, query database, send authentication information.

8/20/2015B.Ramamurthy11 HTTPServlet Methods service: This is called when a request arrives at a server. This method in turn calls doXYZ. doGet : responds to HTTP GET ; get information to browser doPOST: responds to HTTP POST : send request to server doDelete : responds to HTTP DELETE : to delete a file on server! doOptions : responds to HTTP OPTIONS doPut : responds to HTTP PUT : to save a file doTrace: called in response to HTTP TRACE for debugging purposes

8/20/2015B.Ramamurthy12 Your Servelet Your servlet will typically extend class HTTPServlet. You will override doGet, doPost and anyother methods of HTTPServlet. Place it n webpages/WEB-INF/servlets Example:/web/faculty/bina/webpages/WEB-INF/servlets Html file acessing the servlet in your regular web pages home.

8/20/2015B.Ramamurthy13 Servlet Semantics The webserver that executes that executes a servlet creates an HTTPServletRequest object and passes it to the servlet’s service method which in turn passes it to doGet. This object contains request from the client. Webserver executes the request and creates HTTPServletResponse object and passes this to the client using doPOST. The object contains response to the client’s request.

8/20/2015B.Ramamurthy14 HTTPServletRequest String getParameter (String name) Enumeration getParameterNames() String[] getParameterValues(String name) Cookie[] getCookies() HttpSession getSession(boolean create)

8/20/2015B.Ramamurthy15 HTTPServletResponse void addCookie(Cookie cookie) ServletOutputStream getOutputStream() PrintWriter getWriter() void setContentType(String type)

More on JSP syntax and contents HTML code for user interface lay out JSP tags: declarations, actions, directives, expressions, scriplets JSP implicit objects: a request object, response object, session object, config object Javabeans: for logic that can be taken care of at the JSP level. We will examine only JSP tags here.

JSP Tags Declaration: variable declaration Directive: ex: import classes Scriplet: Java code <% if password(“xyz”) { %> Welcome Expression: regular expression using variables and constants Action: <jsp:usebean name =“cart” class=“com.sun.java.cart”

Java Server Pages by Examples JSPs combine static markup (HTML, XML) with special dynamic scripting tags. Each JSP is translated into a servlet the first time it is invoked. Then on, the requests are serviced by the servlets. Lets understand the building blocks of a JSP, namely, directives, scripting elements, and actions through a series of examples.

Examples: Directives A directive configures the code generation that container will perform in creating a servlet. Simple JSP showing access to a Java API class Date: simple.jsp Using Page directives to define various page attributes: pageDirective.jsp Directive to include other JSPs: includeDirective1.jsp, includeDirective2.jsp

Examples: Scripting Elements Declaration: A declaration is a block of code in a JSP that is used to define class-wide variables and methods in the generated servlet. Declaring a piece of code: declaration.jsp

Examples: Scripting Elements (contd.) Scriplets: A scriplet is a block of Java code that is executed during the request-processing time. See scriplet.jsp Expressions: sends a value of a Java expression back to the client. See expression.jsp

Examples: Standard Actions Standard actions are well known tags that affect the run time behavior of the JSP and the response sent back to the client. Some commonly used tag actions types are: