SSC - Web applications and development Introduction and Java Servlet (I)

Similar documents
SSC - Web development Model-View-Controller for Java Servlet

Java Enterprise Edition. Java EE Oct Dec 2016 EFREI/M1 Jacques André Augustin Page 1

JAVA SERVLET. Server-side Programming INTRODUCTION

Servlet Fudamentals. Celsina Bignoli

Advanced Internet Technology Lab # 4 Servlets

INTRODUCTION TO SERVLETS AND WEB CONTAINERS. Actions in Accord with All the Laws of Nature

Servlets and JSP (Java Server Pages)

Enterprise Java Unit 1- Chapter 3 Prof. Sujata Rizal Introduction to Servlets

Servlets1. What are Servlets? Where are they? Their job. Servlet container. Only Http?

Developing Applications with Java EE 6 on WebLogic Server 12c

Session 8. Introduction to Servlets. Semester Project

Ch04 JavaServer Pages (JSP)

Developing the First Servlet

Advanced Web Technology

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

The Basic Web Server CGI. CGI: Illustration. Web based Applications, Tomcat and Servlets - Lab 3 - CMPUT 391 Database Management Systems 4

CIS 455 / 555: Internet and Web Systems

Java Servlets. Preparing your System

Session 9. Introduction to Servlets. Lecture Objectives

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

LAB 1 PREPARED BY : DR. AJUNE WANIS ISMAIL FACULTY OF COMPUTING UNIVERSITI TEKNOLOGI MALAYSIA

Database Applications Recitation 6. Project 3: CMUQFlix CMUQ s Movies Recommendation System

SERVLETS INTERVIEW QUESTIONS

Servlet Basics. Agenda

Introduction to JSP and Servlets Training 5-days

Servlets by Example. Joe Howse 7 June 2011

Module 3 Web Component

Enterprise Java Technologies (Part 1 of 3) Component Architecture. Overview of Java EE. Java Servlets

Enterprise Java Unit 1- Chapter 4 Prof. Sujata Rizal Servlet API and Lifecycle

This tutorial will teach you how to use Java Servlets to develop your web based applications in simple and easy steps.

Web based Applications, Tomcat and Servlets - Lab 3 -

sessionx Desarrollo de Aplicaciones en Red A few more words about CGI CGI Servlet & JSP José Rafael Rojano Cáceres

Advance Java. Configuring and Getting Servlet Init Parameters per servlet

Copyright 2014 Blue Net Corporation. All rights reserved

Distributed Multitiered Application

Advanced Topics in Operating Systems. Manual for Lab Practices. Enterprise JavaBeans

Introduction to Java Servlets. SWE 432 Design and Implementation of Software for the Web

ICOM 5016 Database Systems. Database Users. User Interfaces and Tools. Chapter 8: Application Design and Development.

SECTION II: JAVA SERVLETS

HttpServlet ( Class ) -- we will extend this class to handle GET / PUT HTTP requests

CNIT 129S: Securing Web Applications. Ch 3: Web Application Technologies

COMP9321 Web Application Engineering

UNIT-V. Web Servers: Tomcat Server Installation:

Contents. 1. JSF overview. 2. JSF example

This course is intended for Java programmers who wish to write programs using many of the advanced Java features.

Upload to your web space (e.g., UCSC) Due this Thursday 4/8 in class Deliverable: Send me an with the URL Grading:

Unit 5 JSP (Java Server Pages)

Webservices In Java Tutorial For Beginners Using Netbeans Pdf

CPET 581 E-Commerce & Business Technologies. Topics

1Z Java EE 6 Web Component Developer Certified Expert Exam Summary Syllabus Questions

Implementation Architecture

Distributed Systems 1

CSC309: Introduction to Web Programming. Lecture 8

Servlets Basic Operations

Using Java servlets to generate dynamic WAP content

4.1 The Life Cycle of a Servlet 4.2 The Java Servlet Development Kit 4.3 The Simple Servlet: Creating and compile servlet source code, start a web

Introduction. This course Software Architecture with Java will discuss the following topics:

Review. Fundamentals of Website Development. Web Extensions Server side & Where is your JOB? The Department of Computer Science 11/30/2015

Web Presentation Patterns (controller) SWEN-343 From Fowler, Patterns of Enterprise Application Architecture

Web Programming Paper Solution (Chapter wise)

Lab session Google Application Engine - GAE. Navid Nikaein

Questions and Answers

ADVANCED JAVA COURSE CURRICULUM

Java Card 3 Platform. Peter Allenbach Sun Microsystems, Inc.

AJP. CHAPTER 5: SERVLET -20 marks

2 Apache Wink Building Blocks

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

UIMA Simple Server User Guide

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

Developing Ajax Web Apps with GWT. Session I

Introduction Haim Michael. All Rights Reserved.

Implementation Architecture

Fast Track to Java EE 5 with Servlets, JSP & JDBC

Cloud Computing Platform as a Service

Servlet. 1.1 Web. 1.2 Servlet. HTML CGI Common Gateway Interface Web CGI CGI. Java Applet JavaScript Web. Java CGI Servlet. Java. Apache Tomcat Jetty

Development of web applications using Google Technology

Introduction. Literature: Steelman & Murach, Murach s Java Servlets and JSP. Mike Murach & Associates Inc, 2003

Stateless -Session Bean

An excellent explanation of how web browsers work:

Java Enterprise Edition

Java EE 6: Develop Web Applications with JSF

Say goodbye to the pains of Ajax. Yibo

Setup and Getting Startedt Customized Java EE Training:

COMP9321 Web Application Engineering

CS506 Web Design & Development Final Term Solved MCQs with Reference

Java servlets CSCI 470: Web Science Keith Vertanen Copyright 2013

CE212 Web Application Programming Part 3

Session 12. RESTful Services. Lecture Objectives

Chapter 10 Servlets and Java Server Pages

To follow the Deitel publishing program, sign-up now for the DEITEL BUZZ ON-

Free Downloads Java Servlet & JSP Cookbook

Session 9. Deployment Descriptor Http. Reading and Reference. en.wikipedia.org/wiki/http. en.wikipedia.org/wiki/list_of_http_headers

Writing Servlets and JSPs p. 1 Writing a Servlet p. 1 Writing a JSP p. 7 Compiling a Servlet p. 10 Packaging Servlets and JSPs p.

Apache Wink Developer Guide. Draft Version. (This document is still under construction)

PHP Development for ClearPath. Session 3028, Tuesday, May 15, 2012, 10:30AM Ron Neubauer, Principal Engineer, Unisys Corporation

AN ISO 9001:2008 CERTIFIED COMPANY ADVANCED. Java TRAINING.

IBM JZOS Meets Web 2.0

Component-Based Software Engineering. ECE493-Topic 5 Winter Lecture 26 Java Enterprise (Part D)

Java EE Application Assembly & Deployment Packaging Applications, Java EE modules. Model View Controller (MVC)2 Architecture & Packaging EJB Module

Database Systems Lab. 11. JSP I 충남대학교컴퓨터공학과 데이타베이스시스템연구실

Transcription:

SSC - Web applications and development Introduction and Java Servlet (I) Shan He School for Computational Science University of Birmingham Module 06-19321: SSC

Outline Outline of Topics What will we learn Web development Java servlet Java servlet: our first example

What will we learn What is web applications and development? Java Servlet: basic concepts, configure, install and use servlet based web applications, basic implementation. Java Serve Pages Java Model View Controller (MVC) for Java Servlet Advanced topics: Spring, JavaServer Faces, Multithreaded Servlet

Web development What is web applications and development? Web-based application: an application that uses a web browser as a client, e.g., google calendar or GMail. Web development: work involved in developing a web site for the Internet or intranet, which include: web design web content development client-side/server-side scripting Web development scripts: Client side: HTML5, JavaScript, Ajax (Asynchronous JavaScript), Flash, JavaFX, etc. Server side: PHP, Python, Node.js, Java servlet Client-side/Server-side: Google Web Toolkit

Java servlet What is Java servlet? Java servlet: a Java platform technology for extending the functionality of a Web server and for accessing existing business systems, part of the Java Enterprise Edition Component-based, server/platform-independent method for building Web-based applications Can use entire family of Java APIs, also can use existing POJOs (Plain Old Java Objects) Using Java servlet, you can generate dynamic web pages based on: data submitted by the user, e.g., results pages from search engines and Google calendar the data changes frequent, e.g., news headlines page or weather report information from corporate databases or other such sources, e.g., online store such as Amazon

Java servlet Why use Java servlet? Efficient: the dynamic web pages are easier to write and faster to run. Convenient: you can use your familiar language Java Powerful: Java servlets provide all the powerfull features of JAVA, such as multi-threads, exception handling and garbage collection. Portable: Servlets are written in Java and can run across Web Servers without changes on Apache or Microsoft IIS. Versatile: you can communicate with different servlet and servers. Inexpensive: Running servlets only requires Java, Apache or Tomcat, which are all free.

Java servlet Java servlet vs other Web development script Java vs PHP vs Perl vs Python Note: Java is statically typed language: types are associated with a variable declaration Note: While PHP/Perl/Python are dynamically typed language, e.g., it does not associate values strictly with a specific type Advantages: Statically typed language ensures earlier detection of errors during compiling Many third party libraries for Java Web development Modern Java Web Development framework such as Spring is robust and convenient Java provide power multithreaded features Java is faster than PHP and other languages

Java servlet Java servlet life cycle Java Servlets are run inside a Servlet compatible Servlet Container, e.g., Apache Tomcat, JBoss, Jetty, etc. A Servlets s life cycle consists of the following steps: Step 1: Load Servlet Class. Step 2: Create Instance of Servlet. Step 3: Call the servlets init() method. Step 4: Call the servlets service() method. Step 5: Call the servlets destroy() method. Note 1: By default, a servlet is not loaded until the first request is received for it. Note 2: When the servlet container unloads the servlet, destroy() method is called and the container finalises the servlet and collect garbage.

Java servlet Java servlet life cycle Servlet Container Load class Instantiation Instantiation Instantiation init() service() Response Request destroy() Finalisation and garbage collection

Java servlet: our first example How to set up your programming IDE What are required? Java EE A Servlet Container, e.g., Apache Tomcat You need to read how to run tomcat from school s support web I am using Eclipse to show you how to build your first servlet but you can also use NetBean. See a tutorial here

Java servlet: our first example Creating your first servlet Create a new Dynamic Web project : File menu New Dynamic Web Project Enter the project name Choose Target Runtime, e.g., Tomcat X.x Choose Dynamic web module version depends on your Servlet API version (Servlet 3.0 for Java EE6+ and Tomcat 7) Tick Generate web.xml deployment descriptor Create a new Sevlet which will extend class HttpServlet Write methods for each HTTP method (GET, POST etc.)

Java servlet: our first example Java servlet explained: HTTP methods Recalled what we learned: HTTP (Hypertext Transfer Protocol) protocol has the following methods: GET(), POST(), HEAD(), PUT(), DELETE(), etc. The most useful two: GET() : Requests data from a specified resource (server) POST() : Submits data to be processed to a specified resource (server) Note: In a GET request, query strings (name/value pairs) is sent in the URL, which can be cached, bookmarked, remained in the browser history, have length restrictions GET requests should be used only to retrieve non-sensitive data Comparison between GET and POST

Java servlet: our first example Java servlet explained: HttpServlet class In Java, your servlet classes extend the HttpServlet abstract class Two most important methods: doget() : to respond HTTP GET requests only dopost() : to respond HTTP POST requests only From one method you can call the other method to handle both GET and POST requests, e.g., Both methods required two parameters: doget(httpservletrequest request, HttpServletResponse response) Two parameters are two classes with a lot of methods to process HTTP requests and responses

Java servlet: our first example Java servlet explained: HttpRequest class Provides request information for HTTP servlets. Request Parameters: sent as part of the URL (in the query string ), or as part of the body of an HTTP request. http://georgewbush.com/mytopsecrets.html? Action=showme&Document=NuclearLaunchCodes A query string of two parameters with parameter values: Action=showme Document=NuclearLaunchCodes getparameternames : Returns the value of a request parameter as a String, or null if the parameter does not exist. getparameter : Returns an Enumeration of String objects containing the names of the parameters in the query string.

Java servlet: our first example Java servlet explained: HttpResponse class Provides HTTP-specific functionality in sending a response setheader : Set HTTP Header, e.g., response.setheader("header-name", "Header Value"); getwriter() : Returns a PrintWriter from the HttpResponse object, so the server can send character text to the client. Use PrintWriter to send plain text or HTML: PrintWriter writer = response.getwriter(); writer.write("<html><body>html reponse</body></html>"); getoutputstream : Returns a ServletOutputStream for writing binary data in the response. sendredirect : Sends a temporary redirect response to the client using the specified redirect location URL