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

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

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

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

Servlets. An extension of a web server runs inside a servlet container

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

JAVA SERVLET. Server-side Programming INTRODUCTION

2. Follow the installation directions and install the server on ccc. 3. We will call the root of your installation as $TOMCAT_DIR

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

CE212 Web Application Programming Part 3

COMP9321 Web Application Engineering

Servlets by Example. Joe Howse 7 June 2011

Web based Applications, Tomcat and Servlets - Lab 3 -

COMP9321 Web Application Engineering

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

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

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

Accessing EJB in Web applications

Java Server Pages, JSP

Session 8. Introduction to Servlets. Semester Project

Advanced Internet Technology Lab # 4 Servlets

Stateless -Session Bean

Welcome To PhillyJUG. 6:30-7:00 pm - Network, eat, find a seat 7:00-7:15 pm - Brief announcements 7:15-8:30 pm - Tom Janofsky's presentation

Chapter 2 How to structure a web application with the MVC pattern

Component Based Software Engineering

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

Session 9. Introduction to Servlets. Lecture Objectives

Developing a Mobile Web-based Application with Oracle9i Lite Web-to-Go

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

CS433 Technology Overview

JavaServer Pages (JSP)

Servlet and JSP Review

Problems in Scaling an Application Client

Servlets and JSP (Java Server Pages)

TUTORIAL QUESTION BANK

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

ServletConfig Interface

Java4570: Session Tracking using Cookies *

Lab session Google Application Engine - GAE. Navid Nikaein

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

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

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

A.1 JSP A.2 JSP JSP JSP. MyDate.jsp page contenttype="text/html; charset=windows-31j" import="java.util.calendar" %>

How to structure a web application with the MVC pattern

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

Developing Applications with Java EE 6 on WebLogic Server 12c

Servlet Basics. Agenda

Scheme G Sample Question Paper Unit Test 2

Ch04 JavaServer Pages (JSP)

CSC309: Introduction to Web Programming. Lecture 11

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

Get the cookies from the service request: Cookie[] HttpServletRequest.getCookies() Add a cookie to the service response:

Web. 2 Web. A Data Dependency Graph for Web Applications. Web Web Web. Web. Web. Java. Web. Web HTTP. Web

Chapter 2 FEATURES AND FACILITIES. SYS-ED/ Computer Education Techniques, Inc.

Web Programming. Lecture 11. University of Toronto

Principles and Techniques of DBMS 6 JSP & Servlet

Java.. servlets and. murach's TRAINING & REFERENCE 2ND EDITION. Joel Murach Andrea Steelman. IlB MIKE MURACH & ASSOCIATES, INC.

Advanced Web Technology

Session 8. JavaBeans. Reading & Reference. Reading. Reference. Session 8 Java Beans. 2/27/2013 Robert Kelly, Head First Chapter 3 (MVC)

Inf 202 Introduction to Data and Databases (Spring 2010)

Handout 31 Web Design & Development

Module 4: SERVLET and JSP

a. Jdbc:ids://localhost:12/conn?dsn=dbsysdsn 21. What is the Type IV Driver URL? a. 22.

WHITE LABELING IN PROGRESS ROLLBASE PRIVATE CLOUD

Java Training Center, Noida - Java Expert Program

CS506 Web Design & Development Final Term Solved MCQs with Reference

Outline. Project Goal. Overview of J2EE. J2EE Architecture. J2EE Container. San H. Aung 26 September, 2003

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

Implementation Architecture

Introduction to Servlets. After which you will doget it

XML and XSLT. XML and XSLT 10 February

SDN Community Contribution

Distributed Multitiered Application

Advanced Java Programming

Experiment No: Group B_2

AIM. 10 September

Implementation Architecture

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

AJP. CHAPTER 5: SERVLET -20 marks

Vision of J2EE. Why J2EE? Need for. J2EE Suite. J2EE Based Distributed Application Architecture Overview. Umair Javed 1

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

GUJARAT TECHNOLOGICAL UNIVERSITY

JavaServer Pages. Juan Cruz Kevin Hessels Ian Moon

JAVA SERVLET. Server-side Programming PROGRAMMING

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

Supplement IV.E: Tutorial for Tomcat For Introduction to Java Programming By Y. Daniel Liang

Database Application Development

Java E-Commerce Martin Cooke,

Exercise. (1) Which of the following can not be used as the scope when using a JavaBean with JSP? a. application b. session c. request d.

Unit 4 - Servlet. Servlet. Advantage of Servlet

Java Server Page (JSP)

Advantage of JSP over Servlet

Session 10. Form Dataset. Lecture Objectives

1.264 Lecture 15. Web development environments: JavaScript Java applets, servlets Java (J2EE) Active Server Pages

SWE642 Oct. 22, 2003

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

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

Unit-4: Servlet Sessions:

J2EE for Oracle Technologists

3. The pool should be added now. You can start Weblogic server and see if there s any error message.

J2EE Web Development 13/1/ Application Servers. Application Servers. Agenda. In the beginning, there was darkness and cold.

Transcription:

Introduction This course Software Architecture with Java will discuss the following topics: Java servlets Java Server Pages (JSP s) Java Beans JDBC, connections to RDBMS and SQL XML and XML translations These tools will then be used to construct webapplications according to different models. Literature: Steelman & Murach, Murach s Java Servlets and JSP. Mike Murach & Associates Inc, 2003 Software: J2SE, Java Standard Edition, version 1.4.x Tomcat, www.apache.org, we use version 4.1.18 MySQL, www.mysql.org All of this is freeware and can be downloaded, (or installed from the CDROM that comes with the book) Introduction 15 January 2004 1 Introduction 15 January 2004 2

What is a web application? That is a set of web pages that are generated in response to a user request. Examples: A browser that requests html-pages from a server. In the simplest case, these pages are static. A browser that requests dynamic pages from a server. These can be generated by PHP or some similar system. This kind of system is called a thin client since the processing is done in the web server. request response Browser Server PHP Browser request response Server A browser that requests dynamic pages from a server. The server somehow forwards these requests to a web-container that generates and returns html-pages. A browser that executes one or more Java applets. This is all done inside the browser (the client), therefore this is known as a fat client. Browser Server Webappcontainer RDBMS We are to discuss the last kind of systems. browser javaplugin Introduction 15 January 2004 3 Introduction 15 January 2004 4

Why do we need a special webcontainer? An application may result in several request/response pairs. Since HTML is stateless (has no memory), we need something that can create resources, remember and identify connections and keep resources alive. An example of a webcontainer is Jakarta Tomcat. It is not a complete J2EE container, it can therefore be called a servlet container. There is a standard framework definition for Javabased webcontainers. This is known as J2EE, The Java2 Enterprise Edition. Servlets and JSP s are part of the J2EE specification. We will use version 2.3 of the Servlet spec. and 1.2 of the JSP specification. What is a servlet? A servlet is a Java class that is derived from the HTTPServlet class. It is executed on behalf of the webserver when requested from a user. The servlet receives the request, and produces html code that is returned via the response mechanism. Since the servlet is a program it can generate dynamic html code based on different condititions. Since this is pure Java it is transportable and follows an official standard. It is multithreaded and only one instansiation is needed. Tomcat implements part of the J2EE specification but not all of it. Introduction 15 January 2004 5 Introduction 15 January 2004 6

A simple servlet can look like package serv; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Serv extends HttpServlet { public void doget(httpservletrequest request, HttpServletResponse response) throws IOException, ServletException { response.setcontenttype( text/html ); PrintWriter out = response.getwriter(); out.println( <H1> hello </H1> ); This will receive a request and generate an HTML headerline as response to the browser. To compile this you need some jar-files that are not part of the J2SE, but they are included in tomcat and in J2EE implementations. To run it you need Tomcat or some other container. Tomcat can execute the servlet directly on reqeust from the browser, but the normal use of a servlet is as part of a deployed application. A deployed application is a complete system with different components that are kept together with a description file. public void dopost(httpservletrequest request, HttpServletResponse response) throws IOException, ServletException { doget(request, response); Introduction 15 January 2004 7 Introduction 15 January 2004 8

What is a JSP? Java Server Pages consists of HTML-code, Java code embedded in a script language (NOT Javascript!) and other JSP tags. The purpose of a JSP is to generate HTML code. Technically a JSP is compiled into a servlet by the webcontainer. Since it is Java it is transportable, but you do not need to compile it, therefore it is easier to work with. JSP is extentable, i. e. you can introduce new tags that extends the functionality of JSP. An example of a JSP is: <HTML> <!-- Copyright (c) 1999 The Apache Software Foundation. All rights reserved.--> <HEAD><TITLE> Calendar: A JSP APPLICATION </TITLE></HEAD> <BODY BGCOLOR= white > <jsp:usebean id= table scope= session class= cal.t ablebean /> <% String time = request.getparameter ( time ); %> <FONT SIZE=5> Please add the following event: <BR> <h3> Date <%= table.getdate() %> <BR> Time <%= time %> </h3> </FONT> <FORM METHOD=POST ACTION=cal1.jsp> <BR> <BR> <INPUT NAME= date TYPE=HIDDEN VALUE= curr ent > <BR> <INPUT NAME= time TYPE=HIDDEN VALUE=<%= time %> <BR> <h2> Description of the event <INPUT NAME= description TYPE=TEXT SIZE=20> </h2> <BR> <INPUT TYPE=SUBMIT VALUE= submit > </FORM></BODY></HTML> Introduction 15 January 2004 9 Introduction 15 January 2004 10

What is a Bean? A Bean is an ordinary Java class that adheres to the Bean rules. Beans can be used for anything, but in a webapplication they are often used to perform datahandling. An example: package test; public class TestBean { String name; Integer age; What is JDBC, RDBMS and SQL? JDBC (Java DataBase Connectivity) is a serverbased, pure Java piece of software that allows Java classes to connect to a database and to perform queries and updates via SQL-statements. Each RDBMS (Relation Database managing System) requires a vendor specific JDBC driver. SQL (Standard Query Language) is a language that allows you to maintain your database. You can store and retrieve data. public TestBean() { public String getname() { return name; public void setname(string newname) { name = newname; public Integer getage() { return age; public void setage(integer newage) { age = newage; Introduction 15 January 2004 11 Introduction 15 January 2004 12

What is XML? XML (Extensible Markup Language) is a markup language that is mainly used to store structured data. It is somewhat similar to HTML but there is no predefined tags. You can use any tags, but you must yourself assign meaning to the tags. The benefit of XML is that it can be translated into other formats, i. e. HTML, PDF etc. Therefore it can be used as a general, transportable format. XML can be translated into HTML by XSLT, Extensible Style Language Translations. An example: <?xml version= 1.0 encoding= ISO8859-1?> <?xml-stylesheet type= te xt/xsl href= employees.xsl?> <employees> <employee empid= 1 > <name>fredrik Ålund</name> <department depid= 3 >Services</department> </employee> <employee empid= 2 > <name>helena Larsson</name> <department depid= 3 > Services </department> </employee> </employees> Case sensitive, more strict than HTML. You must use closing tags for ALL elements. Introduction 15 January 2004 13 Introduction 15 January 2004 14

How do you combine these into an application? One way to organize this is the MVC model. This means Model, View and Control. Model is the datahandling and business logic View is the presentation, i. e. the HTML pages Control is the scheduler, the one that distributes the work. XML-files are used to describe the application. Beans are good to obtain and maintain data. They can connect to databases to get/store data. Since they are pure Java you have the full power of the language with all datatypes. JSP s are used to produce HTML. In addition you can embed JAVA in a JSP. However this makes them more difficult to read and to maintain because you mix a number of languages. Therefore they are most often used to produce presentation, i. e. HTML, of data produced by some beans. Servlets are used as control. They receive the requests from the client, distributes the work to JSP s and beans and return the response. Usually you avoid generating HTML in the servlet because too much of that makes the servlet cluttered with strange HTML-strings hard to maintain. Introduction 15 January 2004 15 Introduction 15 January 2004 16

We have no special development tools available here but there are such tools: Browser Full J2EE tools Oracle JDeveloper. Complete environment, arbitrary database. Free for personal use. High quality. Se www.oracle.com Servlets JSP s Borland Jbuilder Enterprise. A 30-day trial version can be downloaded from www.borland.com Eclips, Open Source but need plugins. www.eclipse.org Just JSP and Servlets: Sun Java Studio standard, www.sun.com Beans NetBeans, www.netbeans.org XML-file RDBMS textfile Introduction 15 January 2004 17 Introduction 15 January 2004 18