111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.

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

Introduction to Servlets Based on: Hall, Brown, Core Servlets and JavaServer Pages.
J.Sant Servlets Joseph Sant Sheridan Institute of Technology.
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
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
JSP Java Server Pages Reference:
Core Servlets Chapter 3 Link for Core Servlets code: om/archive/ om/archive/
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,
Comp2513 Java Servlet Basics Daniel L. Silver, Ph.D.
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
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.
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.
A Servlet’s Job Read explicit data sent by client (form data) Read implicit data sent by client (request headers) Generate the results Send the explicit.
CSCI 6962: Server-side Design and Programming History and Background.
Java Servlets and JSP.
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.
1 Servlet How can a HTML page, displayed using a browser, cause a program on a server to be executed?
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
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.
Java support for WWW Babak Esfandiari (sources: Qusay Mahmoud, Roger Impey, textbook)
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.
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.
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. Servlets When we run small Java programs within a browser these are referred to as Applets... And when we run small Java programs within.
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.
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.
@2008 Huynh Ngoc Tin Chapter #2 JAVA SERVLET PRGRAMMING.
Java Servlets and Java Server Pages Norman White Stern School of Business.
Installing and Configuring Tomcat SSE. Downloading Tomcat l Download url: 4.0/release/v4.1.24/bin/
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.
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.
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,
How CGI and Java Servlets are Run By David Stein 14 November 2006.
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.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
Distributed Web Systems Java Servlets Lecturer Department University.
Introduction to Servlets
CS3220 Web and Internet Programming Introduction to Java Servlets
Net-centric Computing
Course Outcomes of Advanced Java Programming AJP (17625, C603)
Servlets Hits Counter 20-Jul-18.
COP 4610L: Applications in the Enterprise Spring 2005
COP 4610L: Applications in the Enterprise Spring 2005
Java Servlets and JSP.
CS3220 Web and Internet Programming Introduction to Java Servlets
Directories and DDs 25-Apr-19.
Basic servlet structure
Directories and DDs 21-Jul-19.
Directories and DDs 14-Sep-19.
Presentation transcript:

111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration for Servlet Processing Starting and Stopping Tomcat Service

222 Dynamic Web Pages The URL points to an “executable program” file instead of to a “static” HTML document file The program generates response based on input request parameters and data stored on the server It writes response in HTML format to stdout These programs can be scripts PERL, PHP, etc or compiled C CGI programs They can also be Java Programs, e.g. Servlets Servlets can be auto-generated from JSP pages

33 Servlets versus Java Server Pages A servlet is a.java source file with code that reads user submitted parameters and writes HTML formatted text back to the user It can also access or update files on the server Much like any Java program: –It is compiled to a.class file –Data is displayed to user based on java statements

44 Servlets versus Java Server Pages A Java Server Page is a “markup document” with snippets of Java code included to control processing/generation of response to the user It can also access or update files on the server Much like any HTML page: –It is not compiled by the developer (a servlet is generated and compiled behind the scenes) –Data is displayed to user based on markup text

55 Servlets versus Java Server Pages There are advantages and disadvantages for using a servlet or a Java Server Page (JSP) Primarily consider the ratio of code to markup: –The more code the greater the case for a servlet –The more markup the greater the case for a JSP The code sections of a JSP may become difficult to debug because the compiler works on the generated ".java" source file - not directly on the JSP For a page with simple server-side functions, such as altering output based on a few request parameters, a JSP can be much simpler to build than a servlet

66 Java Servlets Import javax.servlet.* and javax.servlet.http.* Class extends httpServlet (An abstract class) No need to implement a constructor method Use methods init and destroy – like Applets Implement methods doPost and/or doGet Compile your servlet source code as usual Save class file in myapp/WEB-INF/classes 6

777 Java Servlets GET method –If your form has METHOD="Get" in its FORM tag, implement the doGet method POST method –If your form has METHOD="Post" in its FORM tag, implement the doPost method For flexibility, implement both methods –Have one method call the other passing the received arguments so you don’t need to write the code twice

888 Java Servlets Example F15.html sends either Get or Post request To localhost/myapp/F15 (a Servlet) Tomcat servlet container invokes either the doGet method or doPost method depending on the type of request received doGet/doPost obtains the input data via calls to the request object’s getParameter method Generates HTML response via response object’s methods and PrintWriter object obtained from response.getWriter method

9 F15 Class import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; public class F15 extends HttpServlet { 9

10 F15 doGet Method public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } 10

11 F15 doPost Method public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // get the input data from the form String name = request.getParameter("Name"); String title = request.getParameter("Title"); String model = request.getParameter("Model");... 11

12 F15 doPost Method // start the usual stuff for the response response.setContentType("text/html"); PrintWriter out = response.getWriter(); // PrintWriter is the same class as System.out String docType = “<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0” + “Transitional//EN\”>\n”; out.println(docType + “ \n” + “ F15 Response ” + “ \n ”); 12

13 F15 doPost Method // now compose our response based on the form input data out.println("To: " + name + " " + title); out.println(" We at MakDonut-Duglass wish you the ” + “best of luck using your F15 " + model + " model to " +... // and end with the usual stuff for the response out.println(" "); } 13

14 Tomcat File Directory Structure Path to Tomcat in Program Files C:\Program Files\Apache Software Foundation\Tomcat 6.0 Top Level Subdirectories of Interest \conf – contains configuration files in xml format \webapps – contains ROOT and “myapp” sub-directories for the top level pages of web applications \work – contains source code and class files for servlets generated from JSP pages (many levels below) \logs – contains log files with error messages or output from any debug write statements you use in your code

15 Tomcat Configuration Tomcat has overall configuration files in: –Tomcat 6.0\conf folder server.xml tomcat-users.xml context.xml web.xml Tomcat has configuration files for individual web applications in: –Tomcat 6.0\webapps\myapp\WEB-INF web.xml

16 Tomcat Configuration (server.xml) Contains configuration for port number on which the service will be offered <Connector port=“80” protocol=“HTTP/1.1” connectionTimeout=“20000” redirectPort=“8443” /> Default file came set up with port 8080

17 Tomcat Configuration (tomcat-users.xml) User account names, passwords and privileges <user username=“admin” password=“********” roles=“admin,manager”/>

18 Tomcat Configuration (context.xml) Context Useful for Development Activity Reloadable = Enables monitoring of servlet class files for reloading without server restart Privileged = Allows Use of Invoker Servlet –Allows access to servlets without a definition and a mapping in the web.xml configuration file(s) Both normally set to false for production

19 Tomcat Configuration (web.xml) In folder conf/web.xml Invoker Servlet Definition / Initialization jsp org.apache.jasper.servlet.JspServlet fork false xpoweredBy false 3

20 Tomcat Configuration (web.xml) In folder conf/web.xml Invoker Servlet Mapping to URL invoker /servlet/*

21 Tomcat Configuration (web.xml) In folder myapp/WEB-INF/web.xml F15 Servlet Definition / Initialization F15 debug 2

22 Tomcat Configuration (web.xml) In folder myapp/WEB-INF/web.xml F15 Servlet Mapping to URL <servlet-mapping F15 /F15

23 Configure Tomcat Service Can use buttons to start and stop the Tomcat Service