Introduction to Java Servlets

Slides:



Advertisements
Similar presentations
Servlets, JSP and JavaBeans Joshua Scotton.  Getting Started  Servlets  JSP  JavaBeans  MVC  Conclusion.
Advertisements

1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
Apache Tomcat as a container for Servlets and JSP
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.
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.
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
Chapter 4 Servlets Concept of Servlets (What, Why, and How) Servlet API Third-party tools to run servlets Examples of Using Servlets HTML tag with GET.
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 Servlets CS-422. Application Mapping Your servlet application will be mapped to a directory structure: –“myapp” maps to some directory C:/docs/apps/myapp.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
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.
Li Tak Sing COMPS311F. Static attributes in Servlets Since Servlets are also Java classes, you can also use static attributes to store values that can.
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Servlet Lifecycle Lec 28. Servlet Life Cycle  Initialize  Service  Destroy Time.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
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.
Java Servlets and Java Server Pages Norman White Stern School of Business.
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.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
Introduction to Servlets Allen Day. Notes This is a training NOT a presentation Please ask questions Prerequisites.
Advanced Java Session 6 New York University School of Continuing and Professional Studies.
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,
Java Web Applications. WAR Web Archive Introduced with servlet 2.2 specification Portable deployment mechanism for web applications Defines directory.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
Java Servlets References: Karen Anewalt, Mary Washington College.
CS3220 Web and Internet Programming Introduction to Java Servlets
Building Web Apps with Servlets
Servlet Fudamentals.
Java Servlets By: Tejashri Udavant..
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Introduction to Java Servlets on Jakarta Tomcat
HTTP Servlet Overview Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might.
In Class Assg 4 - Solution
In Class Assg 3 - Solution
CHAPTER 10 Servlet Programming
Chapter 26 Servlets.
Jagdish Gangolly State University of New York at Albany
Servlets and JSP 20-Nov-18 servletsJSP.ppt.
Servlets & JSP.
In Class Assg 2 - solution
Introduction to Servlets
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
Java Servlets and JSP.
CS3220 Web and Internet Programming Introduction to Java Servlets
Servlets.
Directories and DDs 25-Apr-19.
Directories and DDs 21-Jul-19.
Directories and DDs 14-Sep-19.
Presentation transcript:

Introduction to Java Servlets Dave Bryson Informs Inc.

Contents 1. What's a Servlet? 2. How's it different from CGI? 3. Lifecycle of a Servlet 4. Scope of a Web application 5. Http Request 6. Http Response 7. Session Management 8. Step by Step 8.1 What you'll need 8.2 Create webapp 8.3 Create the servlet 8.4 Configure web.xml 9. Resources

. What's a Servlet? Java class building off javax.servlet package Extends the capabilites of a web server Gateway into your application

2. How's it different from CGI? Multithreaded Persistent connection J2EE servers everywhere

3. Lifecycle of a Servlet Initialization Service Destroy

4. Scope of a Web application Servlet Context Session Request Page (JSP)

5. Http Request Wrapper object for the incoming request. Provides a single object to access: Parameters Session information Header data

6. Http Response Wrapper object for the outgoing response. Provides a single object to: Get an output stream Add a cookie Set content type Set status codes

7. Session Management Provides state management across requests from the same user. Can be used to: Store objects across requests Used for application security Time out a session

8. Step by Step Subsections 8.1 What you'll need 8.2 Create webapp 8.3 Create the servlet 8.4 Configure web.xml

8.1 What you'll need Java Developer's Kit from Sun - http://java.sun.com Servlet Engine - http://jakarta.apache.org/tomcat Something to write code in - http://www.jedit.org

8.2 Create webapp Under webapps directory, create the following directory structure: mydemo |-- WEB-INF | |- classes | | | |-mydemo web.xml

8.3 Create the servlet Under the classes/mydemo directory create the DemoServlet class: package mydemo; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletException; import java.io.IOException; import java.io.PrintWriter; public class DemoServlet extends HttpServlet { /** * Called once at startup */ public void init() throws ServletException System.out.println("Init() the Servlet"); } public void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException

8.3 Create the servlet { String name = req.getParameter("name"); // Handle a null if ( name == null ) name = "You forget to add name."; } // Set the content type resp.setContentType("text/html"); // Generate the HTML String output = getOutput(name); // Write to the browser PrintWriter writer = null; try writer = resp.getWriter(); writer.write(output); ) catch (IOException e) e.printStackTrace();

8.3 Create the servlet finally { writer.flush(); writer.close(); } private String getOutput( String name ) StringBuffer buffer = new StringBuffer(); buffer.append("<html><body><h2>Hello. Your name is: "); buffer.append(name); buffer.append("</h2></body></html>"); return buffer.toString(); Compile the servlet ( make sure you have the servlet.jar in your classpath ).

8.4 Configure web.xml <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/dtd/web-app_2_2.dtd"> <web-app> <servlet> <servlet-name> Demo </servlet-name> <servlet-class> mydemo.DemoServlet </servlet-class> </servlet> <servlet-mapping> <url-pattern> /Demo </url-pattern> </servlet-mapping> </web-app> Point your browser to http://localhost:8080/mydemo/Demo?name=Dave

9. Resources Sun Microsystems - http://java.sun.com Jakarta Apache - http://jakarta.apache.org Weblogs - http://www.javablogs.com