Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.

Slides:



Advertisements
Similar presentations
Apache Tomcat as a container for Servlets and JSP
Advertisements

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.
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.
MC365 Application Servers: Servlets. Today We Will Cover: What a servlet is The HTTPServlet and some of its more important methods How to configure the.
An introduction to Java Servlet Programming
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
Core Servlets Chapter 3 Link for Core Servlets code: om/archive/ om/archive/
1 CS6320 – Servlet Structure and Lifecycle L. Grewe.
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,
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.
Server Side Programming Web Information Systems 2012.
Definition Servlet: Servlet is a java class which extends the functionality of web server by dynamically generating web pages. Web server: It is a server.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
Java Servlets and JSP.
Java Servlets.
SERVLETS.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
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.
Functionality of a web server What does the web server do? Let a user request a resource Find the resource Return something to the user The resource can.
CSC 2720 Building Web Applications
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
SKT-SSU IT Training Center Servlet and JSP. Chapter Three: Servlet Basics.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
CMPUT 391 – Database Management Systems Department of Computing Science University of Alberta CMPUT 391 Database Management Systems Web based Applications,
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.
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.
S ERVLETS Hits Counter 21-Nov-15. S ERVLETS - H ITS C OUNTER Many times you would be interested in knowing total number of hits on a particular page of.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
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.
CSE 403 The Mythical Servlet Goals Introduce basic servlet terminology Formally introduce homework 2 Walkthrough of build & deployment Group discussion.
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.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
Configuration Web Server Tomcat - Install JDK Install Tom cat Configure Tom cat for running Servlet C:\Program Files\Apache Software Foundation\Tomcat.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
How CGI and Java Servlets are Run By David Stein 14 November 2006.
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 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
Java Servlets References: Karen Anewalt, Mary Washington College.
Distributed Web Systems Java Servlets Lecturer Department University.
Introduction to Servlets
CS3220 Web and Internet Programming Introduction to Java Servlets
Building Web Apps with Servlets
Java Servlets By: Tejashri Udavant..
CSE 403: Servlet Technology
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Servlets Hits Counter 20-Jul-18.
HTTP Servlet Overview Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might.
Servlets and JSP 20-Nov-18 servletsJSP.ppt.
Objectives In this lesson you will learn about: Need for servlets
Java Servlets and JSP.
CS3220 Web and Internet Programming Introduction to Java Servlets
J2EE Lecture 1:Servlet and JSP
Directories and DDs 25-Apr-19.
CS122B: Projects in Databases and Web Applications Winter 2019
Introduction to Servlet
Basic servlet structure
Directories and DDs 21-Jul-19.
Directories and DDs 14-Sep-19.
Presentation transcript:

Java Servlets Lec 27

Creating a Simple Web Application in Tomcat

Tomcat Directory Structure myapp

Tomcat Setup Folder for HTML and JSP pages Folder for servlet and other java classes

Servlet Types Servlets are based on two main packages  javax.servlet  javax.servlet.http GenericServlet  For writing protocol independent servlets HttpServlet  Extends from GenericServlet class  Adds functionality for writing HTTP specific servlets

Servlet class hierarchy Object GenericServletServletResponse HttpServletRequest ServerRequest HttpServletHttpServletResponse javax.servlet javax.servlet.http

Writing Servlet Every servlet must implement the javax.servlet.Servlet interface  Contains the servlet’s life cycle methods etc. These are implemented by GenericServlet and HttpServlet classes Extend your servlet from one of these classes and add your own functionality public class MyServlet extends GenericServlet public class HelloServlet extends HttpServlet

Types of HTTP Requests  Get  Post  Delete  Options  Put  Trace

How HTTP Sends Request Client Server Servlets Some HTTP request types Get -- Attr/Val pairs attached after ? of URL E.g. Post -- Attr/Val pairs attatched with the request body

HTTP Request Example Request parameters etc

Writing Servlet Steps for making a HelloWorldServlet 1. Create a directory structure for your application (myapp). This is a one time process for any application 2. Create a HelloWorldServlet source file by extending this class from HttpServlet and override your desired method 3. Compile it (If compiler complains of not having required packages, check your class paths)

Writing Servlet Steps for making a HelloWorldServlet 1. Place the class file in the classes folder of your webapplication. (myapp) If you are using packages (recommended) then create a complete directory structure under classes folder 2. Create a deployment descriptor ( web.xml ) and put it inside WEB- INF folder 3. Restart your server, if already running 4. Access your application using Web browser

HelloServlet Example Code

HelloWorldServlet import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorldServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println(“Hello World!”); }

web.xml HelloWorldServlet HelloWorldServlet /myfirstservlet

Compiling and Invoking Servlets Compile HelloWorldServlet.java using javac command Put HelloWorldServlet class in install_dir/webapps/myapp/WEB-INF/classes Put web.xml file in install_dir/webapps/myapp/WEB-INF Invoke your servlet by writing following command in the web browser

Lets do it LIVE

Free Servlet and JSP Engines Apache Tomcat  Allaire/Macromedia JRun  New Atlanta ServletExec  Causho’s Resin 