J2EE T ECHNOLOGIES These are the technologies required to build large scale distributed applications, can be divided into – Component Technologies eg.

Slides:



Advertisements
Similar presentations
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Advertisements

COMP 321 Week 8. Overview MVC Example Servlet Lifecycle Servlet Mechanics MVC Lab 5-2 Solution Lab 8-1 Introduction.
Introduction to Servlets Based on: Hall, Brown, Core Servlets and JavaServer Pages.
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
Servlets Stoney Jackson
An introduction to Java Servlet Programming
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 10 Object Oriented Programming in Java Advanced Topics Servlets.
2/16/2004 Dynamic Content February 16, /16/2004 Assignments Due – Message of the Day Part 1 Due – Reading and Warmup Work on Message of the Day.
27-Jun-15 Directories and DDs. 2 Web apps A web application is basically a web site that: “Knows who you are”--it doesn’t just give you static pages,
Introduction to Servlet & JSP
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
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.
Java Servlets and JSP.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Java Servlet Technology. Introduction Servlets are Java programs that run on a Web server, handle HTTP requests and build Web pages Servlet specification.
Servlets Pranav Maydeo. What is a Servlet ? Servlets are modules of Java code that run in a server application to answer client requests. Servlets are.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
Objectives Java Servlet Web Components
CSC 2720 Building Web Applications
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
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 Servlets & Java Server Pages Lecture July 2013.
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
Chapter 2 Web app architecture. High-level web app architecture  When a client request coming in and needs servlet to serve dynamic web content, what.
20-Nov-15introServlets.ppt Intro to servlets. 20-Nov-15introServlets.ppt typical web page – source Hello Hello.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
Copyright © 2002 ProsoftTraining. All rights reserved. Java Servlets.
JSP Pages. What and Why of JSP? JSP = Java code imbedded in HTML or XML –Static portion of the page is HTML –Dynamic portion is Java Easy way to develop.
Middleware 3/29/2001 Kang, Seungwoo Lee, Jinwon. Description of Topics 1. CGI, Servlets, JSPs 2. Sessions/Cookies 3. Database Connection(JDBC, Connection.
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.
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
Introduction to Servlets. Introduction Servlet is a language to develop the server side applications, and it is also server side component. It can develop.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
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.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
Java and the Web CSE 3330 Southern Methodist University.
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 Servlets and Java Server Pages
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
Introduction To HTML Dr. Magdi AMER. HTML elements.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
 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,
JSP JavaServer Pages. What is JSP? Java based technology that simplifies the development of dynamic web sites JSP pages are HTML pages with embedded code.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Chapter 4 Request and Response. Servlets are controlled by the container.
S ERVLETS Form Data 19-Mar-16. F ORM P ROCESSING You must have come across many situations when you need to pass some information from your browser to.
1 Lecture 8 George Koutsogiannakis/Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
Introduction to Servlets
CS3220 Web and Internet Programming Introduction to Java Servlets
Servlets.
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Pre-assessment Questions
Chapter 26 Servlets.
Servlets and Java Server Pages
Java Servlets and JSP.
CS3220 Web and Internet Programming Introduction to Java Servlets
Directories and DDs 25-Apr-19.
Directories and DDs 21-Jul-19.
Directories and DDs 14-Sep-19.
Presentation transcript:

J2EE T ECHNOLOGIES These are the technologies required to build large scale distributed applications, can be divided into – Component Technologies eg. Servlets, JSP, Beans – Service Technologieseg. JDBC – Communication TechnologiesHTTP, TCP/IP, RMI

W EB C ONTAINER Servlets don’t have main method. They are under control of another Java Application called a Container. Eg When a Socket Connection is made, we create socket, identify port to listen request, create streams etc. But container already knows protocol between web server and itself.

S ERVLET D EFINITION A Servlet, in simple terms, is a Java program running under a web server taking a 'request' object as an input and responding back by a 'response' object. Typically a web browser will send the request in HTTP format. The Servlet container will convert that into a request object. Similarly the response object - populated by the Servlet is converted into an HTTP response by the Servlet container.

S ERVLET M ODEL

B ASIC S ERVLET S TRUCTURE Import javax.servlet.*; Import java.io.*; /** * Servlet implementation class FirstServlet */ public class FirstServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub PrintWriter out = response.getWriter(); response.setContentType("text/html"); try { out.println(" HelloWorld "); } finally {out.close(); } 5

WEB. XML maps internal name to fully qualified name URL Hello maps internal name to Public URL name URL /URL 6

B ENEFITS OF M APPING Mapping Servlet Names improves application’s flexibility and security. The Deployment Descriptor provides “declarative” mechanism for customizing web applications without touching Source Code

R EQUEST P ARAMETERS When a request is sent from Jsp Page to Servlet, Parameters set in form are also sent in Request Body for Post Method. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out= response.getWriter(); String Name=request.getParameter("name"); String rollno=request.getParameter("rollno"); ……………… }

Some form input types,like set of CheckBoxes can have multiple selections.To view all selections, getParamterValues(String a) can be used. String[] courses =request.getParameterValues("course"); for(int x=0;x<courses.length;x++) { out.println("Course :" + courses[x]); out.println(" "); }

S ERVLET C ONFIG AND S ERVLET C ONTEXT 11 ServletContext MyServlet1MyServlet2MyServlet3 ServletConfig

S ERVLET C ONFIG One ServletConfig object per servlet Provided to a servlet upon initialization by the web server (container) Can also access ServletContext Parameters are configured in Deployment Descriptor

S ERVLET C ONTEXT One ServletContext per web-app Use it to access web-app parameters Can be used as a global data store (like an application-wide session) Parameters are configured in Deployment Descriptor

I NIT P ARAMETERS Web.xml FirstServlet classes.FirstServlet ID

F IRST S ERVLET. JAVA //Code to get init parameters from Web.xml Private String mailid; public void init(ServletConfig config) throws ServletException { mailid=config.getInitParameter("ID"); }

C ONTEXT P ARAMATERS FirstServlet classes.FirstServlet mailid

S ERVLET C OLLABORATION In a web application, a servlet receives an HTTP request,executes some application logic, and prepares a response but sometimes servlet dosen’t send response. For Below Scenarios: A servlet receives an http request from a client,process application logic and a JSP page drives the response. In this case,JSP is responsible for dynamic content.

Second Scenario: A servlet receives request, processes application logic partially, and hands over response to another servlet.The second servlet completes the application logic, and either prepares the response or request a JSP to drive the response. Note: In both scenarios, servlet which receives request dosen’t deal with response itself.

S OLUTION : Redirect Request to different URL Dispatch Request to some other component in web-app

R EDIRECT Servlet Redirect makes the browser do the work. public void sendRedirect(String Location) Client receives the HTTP response code 302 indicating that temporarily the client is being redirected to specified location.

R EDIRECT R ESPONSE Steps to redirect: a) Client request for a URL in request: b) Servlet logic decides that request should go to a completely different URL c) Servlet calls sendRedirect(String) on response and sends response to client. d) Http response has status code “302” and a “location” header with new URL. e) Browser get response,sees 302 status code and looks for “location” header.

R EQUEST D ISPATCH Request Dispatcher works on Server-side. Steps: a) User types URL into browser b) Request goes to container which transfer request to servlet c) Servlet logic decides that request should go to other web component eg. “.jsp” page d) Servlet calls RequestDispatcher rd= request.getRequestDispatcher("result.jsp"); rd.forward(request, response);

R EQUEST D ISPATCH forward Once you forward the request from say Servlet A to any other Servlet/JSP control gets transferred from Servlet A to forwarded patrty & it never returns back to A for that request. Include In include what you are doing is if Servlet A(Above example) is including the response of other Servlet/JSP(say B or B.jsp) so momentarily Control goes to B or B.jsp (they will genrate the response) control comes back to A & generated response is added in A's Response.Servlet

A TTRIBUTES An attribute is an object set in three other servlet API objects: -Servlet Context -HttpServletRequest -HttpSession Attribute is a name/value pair where name is String and Value is an Object.

S COPE OF A TTRIBUTES Context : Everyone in Application has Access Request : Accessible only to specific servlet request Session : Accessible to components in specific session Method to set Attribute on a Servlet: getServletContext().setAttribute(String Name,Object value) request.setAttribute(String name,Object value) request.getSession().setAttribute(String name, Object value)

Method to get Attributes: - request.getAttribute(String name) - getServletContext().getAttribute(String name) - request.getSession().getAttribute(String name)  Return Type of getAttribute(String) :Object eg Student st= request.getAttribute(“StudentName”);

A TTRIBUTE API Object getAttribute(String name) Void setAttribute(String name,Object Value) Void removeAttribute(String name) Enumeration getAttributeNames()

A RCHITECTURE S TYLE FOR W EB A PP

MVC MVC stands for Model-View-Controller The Model is the actual internal representation of data (Java Classes) The View (or a View) is a way of looking at or displaying the model ( JSP) The Controller provides for user input and modification (Servlets)

A DVANTAGES OF MVC Motivation behind MVC approach is the desire to separate the code that creates and manipulates from the code that represents the data.

C ASE S TUDY