Component Based Software Engineering

Similar documents
COMP9321 Web Application Engineering

COMP9321 Web Application Engineering

Java Server Page (JSP)

JavaServer Pages (JSP)

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

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

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

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

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

CE212 Web Application Programming Part 3

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

Introduction to Java Server Pages. Enabling Technologies - Plug-ins Scripted Pages

JAVA SERVLET. Server-side Programming INTRODUCTION

Advance Java. Configuring and Getting Servlet Init Parameters per servlet

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

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

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

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

Session 8. Introduction to Servlets. Semester Project

Servlets and JSP (Java Server Pages)

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

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

JavaServer Pages. What is JavaServer Pages?

AJP. CHAPTER 5: SERVLET -20 marks

Advanced Web Technology

CS433 Technology Overview

JAVA SERVLET. Server-side Programming PROGRAMMING

Advanced Java Programming

Session 9. Introduction to Servlets. Lecture Objectives

Chapter 10 Servlets and Java Server Pages

COMP9321 Web Application Engineering

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

Servlets by Example. Joe Howse 7 June 2011

ADVANCED JAVA COURSE CURRICULUM

Web based Applications, Tomcat and Servlets - Lab 3 -

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

Advanced Internet Technology Lab # 4 Servlets

Table of Contents. Introduction... xxi

Unit-4: Servlet Sessions:

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

Servlet Fudamentals. Celsina Bignoli

JSP MOCK TEST JSP MOCK TEST IV

Session 20 Data Sharing Session 20 Data Sharing & Cookies

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

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

Unit 4 - Servlet. Servlet. Advantage of Servlet

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

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

Java E-Commerce Martin Cooke,

DVS WEB INFOTECH DEVELOPMENT TRAINING RESEARCH CENTER

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

SERVLETS INTERVIEW QUESTIONS

PSD1B Advance Java Programming Unit : I-V. PSD1B- Advance Java Programming

Component Based Software Engineering

Ch04 JavaServer Pages (JSP)

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

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

112. Introduction to JSP

CS506 Web Design & Development Final Term Solved MCQs with Reference

More JSP. Advanced Topics in Java. Khalid Azim Mughal Version date: ATIJ More JSP 1/42

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

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

UNIT-VI. HttpServletResponse It extends the ServletResponse interface to provide HTTP-specific functionality in sending a response.

Servlet Basics. Agenda

112-WL. Introduction to JSP with WebLogic

Integrating Servlets and JavaServer Pages Lecture 13

Principles and Techniques of DBMS 6 JSP & Servlet

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

How to structure a web application with the MVC pattern

Servlet and JSP Review

INTERNET PROGRAMMING TEST-3 SCHEME OF EVALUATION 1.A 3 LIFE CYCLE METHODS - 3M 1.B HTML FORM CREATION - 2 M

Chapter 10 Web-based Information Systems

Introduction to JSP and Servlets Training 5-days

Module 3 Web Component

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

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

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

Using Java servlets to generate dynamic WAP content

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

Java4570: Session Tracking using Cookies *

Module 4: SERVLET and JSP

COMP9321 Web Application Engineering

1. Introduction. 2. Life Cycle Why JSP is preferred over Servlets? 2.1. Translation. Java Server Pages (JSP) THETOPPERSWAY.

Scope and State Handling in JSP

COMP9321 Web Application Engineering

Java servlets CSCI 470: Web Science Keith Vertanen Copyright 2013

Developing Applications with Java EE 6 on WebLogic Server 12c

A JavaBean is a class file that stores Java code for a JSP

JSP - SYNTAX. Any text, HTML tags, or JSP elements you write must be outside the scriptlet. Following is the simple and first example for JSP:

Distributed Multitiered Application

PES INSTITUTE OF TECHNOLOGY, SOUTH CAMPUS DEPARTMENT OF MCA INTERNAL TEST (SCHEME AND SOLUTION) II

********************************************************************

Advantage of JSP over Servlet

LTBP INDUSTRIAL TRAINING INSTITUTE

Session 10. Form Dataset. Lecture Objectives

Université du Québec à Montréal

CSC309: Introduction to Web Programming. Lecture 11

JavaServer Pages. Juan Cruz Kevin Hessels Ian Moon

Tapestry. Code less, deliver more. Rayland Jeans

Java Server Pages. JSP Part II

Transcription:

Component Based Software Engineering Masato Suzuki School of Information Science Japan Advanced Institute of Science and Technology 1 Schedule Mar. 10 13:30-15:00 : 09. Introduction and basic concepts 15:10-16:40 : 10. Client side components(1) Mar. 11 13:30-15:00 : 11. Client side components(2) 15:10-16:40 : 12. Server side components(1) Mar. 17 13:30-15:00 : 13. Server side components(2) 15:10-16:40 : 14. Frameworks and middlewares Mar. 19 12:30-14:00 : 15. State-of-the-art topics 2

#12 Server side components(1) Contents!! Web application!! Servlet and JSP: dymamic creation of WEB pages 3 Client/Server architecture style Physical structure: A server and multiple (independent) clients Customer submit/cancel!"#$! %&#'"(! show status Manager Functinal req: Submit/cancel from any costomer client at any time Show status report from manager's client. Using GUI and no specical software is required to any clients Non-functional req: Location independent for clients Scalability 4

Client/Server (cont.) Logical structure!! Communicate through request/responce pair.!! Behavior is as same as a regular procedure call. request = new Request(tf.getText(),...); response = server.submit(request); if (response.getstatus() ==... ) Response submit(request request) { DB.add(request.getDay(),... ); } submit/cancel Resv. logic add/update ResvDB Structure of request/response are simple. Building independent server for each app. will raise development costs. 5 WEB Applications We generally employ the style of WEB application for implementation of typical C/S systems.!! WEB browser is easier to use than stand alone app.!! WEB server is more general to provide services. Servlets are used for extention of a WEB server. Web Browser Web Server an applet http a servlet an applet a script script engine a script script engine application services 6

HTTP(HyperText Transfer Protocol) [RFC2616]!! Aimed communication with text documents!! HTML documents are searched/ aquired/ displayed and shared on the WEB.!! Communication is achieved by specifying uniformed location of documents (URL). f1 <a href= http://h2/f2.html >f2</a> h1 f2 GET f1.html HTTP/1.1... GET f2.html HTTP/1.1... h2 7 Scripting Languages!! Describe dynamic operations such as read/write of variables, arith. op. etc.!! Code in JavaScript is performed as a part of browser.!! External scripts are written in Perl/Ruby, executed as another process using the CGI mechiasm. a.class an applet Web Browser a.html <object classid= java:applet > </object> Web Server a.html x.cgi CGI script engine <form action= x.cgi > </form> interpreter 8

CGI mechanism is harmful CGI (Common Gateway Interface) has many problems.!! Overhead caused by running as another process loses the scalability.!! Some parameters encoded as a part of URL may cause severe security issues. Web Browser name pass Send suzuki *** login.html <html> <form action= login.cgi >... <input type= submit name= Send...> </form> </html> invoked as many as the number of clients secret information is exposed login.cgi? ID=suzuki&PW=foo login.cgi DB 9 Servlet: Server side components!! Dynamic extension of WEB servers.!! Independent to platforms (Java VM is required)!! Running on multi-threads reduce overheads.!! Low opportunity to expose secure data. Web Browser Request(*) Web Server (Apache) a servlet a JSP container(tomcat) Response(*) Servlet APIs (*)javax.servlet.http. HttpServletRequest Servlet.class.class 10

Objects for handling Status!! HTTP is transient, no persistent status.!! Status are provided by some (internal) objects!! Container holds these objects. WEB Browser cookie addcookie request param[...] response out WEB Server(Apache/Tomcat) session Attribute application ServletPath config timeout encode getcookie session Attribute exception Message (capacity of cookie is small [< 4KB]) 11 Structure of a Servlet It generates response from request. Writing HTML strings to out makes a page. import java.io.*; import java.servlet.*; import java.servlet.http.*; public class myloginservlet extends HttpServlet { public void doget(httpserveltrequest request, HttpServletResponse response) throws IOException, ServletException { HttpSession session = request.getsession(true); response.setcontexttype("text/html"); PrintWriter out = response.getwriter(); out.println("<html><body>"); out.print("name=");... out.print("pass=");... out.println("</body></html>"); }... response out <html> <body> name=... pass=... </body> </html> 12

Dynamic creation Dynamic creation is achieved by writing variables as the result of some operations. public class VacancyServlet extends HttpServlet { public void doget(httpserveltrequest request, HttpServletResponse response) throws IOException, ServletException { // initializations are omitted String day = request.getparameter( day ); int num = db.getvacancy(day); out.println("<table><tr>"); out.print("vacancy(" + day + )= + num);... out.println("</tr></table>"); }... (Object db is an abstraction of a database.) browser num 3 request response day 10/20 db 20 21 3 4 out <table><tr> vancancy(10/20)=3 </tr></table> vacancy(10/20)=3 13 Problems in Servlet coding!! Servlet is a powerful, flexible mechanism for dynamic creation of WEB pages, but!! Developers must describe many routine codes. They are non-productive works. Eg. create table for vacancy in [10/21,10/30] request from 10/21 db to 20 21... 30 3 4 2 10/30 It is also hard to understand. String from= request.getparameter( from ); String to = request.getparameter( to ); int fromday = DaytoInt(from); int today = DaytoInt(to); out.println("<table>"); for (int d= fromday; d <= today; d++) { num = db.getvacancybyday(d); out.println("<tr>vacancy(" + d + )= + num + </td> ); } out.println("</table>"); 14

From JSP to Servlet!! JSP(Java Server Page) is a scripting language which generates a HTML page dynamically.!! JSP script is converted to servlet code (in Java )!! Expressions/variables can be described. A JSP script (Vacancy.jsp) <% String day =... %> <% int num = db.getvacancy(day); %> <html> <body> <table> vacancy(${day}) = ${num} </table> </body> </html> Complied when it is loaded first. A source of servlet (Vacancy.java) class VacancyServlet extends javax.servlet.httpservlet { public void doget( HTTPServletRequest req, HTTPServletResponce res) {... String day=req.getparameter( day ); int num= db.getvacancy(day); out.print( vancancy( ); out.print(day); out.print( )= );... Pre-compiled, deployed as.class. 15 Usage of JSP(1)!! Inputs are read as parameters from a form generated by another HTML file.!! Outputs are calculated and written in the JSP file. Example: query the number of available (single, twin) rooms date 10/10 query Result 10/10: S1T2 OK index.html <form action="query.jsp"> <table><tr> <td>date</td> <td><input type="text"... ></td> </tr></table> <input type="submit"...> </form> query.jsp read <% String date = param[ date ] %> <% query.jsp String result = getresult(...); %> <h1>result</h1> calculate <table><tr> <td>${date}:</td> write <td>${result}</td> </tr></table> 16

Usage of JSP(2) Transition to another page is achieved by jsp:forward. login.jsp <table><tr> <td> ${param["name"]} </td> <td> ${param[ pass ]} </td> </tr></table> <jsp:forward page= check.jsp /> All outputs are discarded. All parameters are unchanged. check.jsp <% Welcome String name=param["name"]; name suzuki suzuki String pass=param["pass"]; pass *** if (authorize(name,pass)) { %> If we use <jsp:include> instead, Welcome ${name} it back to the previous page after the operation in included file are finished. 17 Usage of JSP(3) It is better to implement complex logics by JavaBeans. usebean create a new instance of external JavaBean and initialize it. setproperty/getproperty are used for interaction to the Bean. calendar.jsp <jsp:usebean id="mycal" class="cal.mycalendar.class" /> <jsp:setproperty name="mycal" property="year" value=... /> <jsp:setproperty name="mycal" property="month" value=... /> <jsp:setproperty name="mycal" property="day" value=... /> <p>result: <jsp:getproperty name="mycal" property="dayofweek" /> </p> mycal setproperty mycal usebean year 2009 month 3 day 1 dayofweek Sunday getproperty 18

MyCalendar.java public class MyCalendar { String year = "1900"; String month = "1"; String day = "1"; String dayofweek = ""; String[] dayname={"","sunday","monday","tuesday","wednesday", "Thursday","Friday","Saturday"}; public MyCalendar() { } public void setyear(string y) { year = y; calc(); } public void setmonth(string m) { month = m; calc(); } public void setday(string d) { day = d; calc(); } public String getdayofweek() { return dayofweek; } private void calc() { java.util.calendar calendar = java.util.calendar.getinstance(); int yy = new Integer(year).intValue(); int mm = new Integer(month).intValue(); int dd = new Integer(day).intValue(); calendar.set(yy,mm-1,dd); int dw = calendar.get(calendar.day_of_week); dayofweek = dayname[dw]; /* exception handling is required */ } }; 19 Summary!! WEB application!! Using WEB brower as a client.!! Using WEB server as a server.!! Extended by applet and servlet respectively.!! Dynamiac creation of WEB pages!! Interact with request and response.!! Inputs are read from the request.!! Outputs are written to out (inside the response)!! Servlet coding is boring, so we generally use JSP.!! JSP can use external JavaBeans. Complex (or secret) logics are implemented in JavaBeans. 20

!! JSP!! Tag libraries!! Database access Next Chapter Client side components (2)!! JavaEE and 3 tier Model!! Business logics!! Persistence for POJO (Plain Old Java Objects) 21 Exercise Review the content of my lecture by answering the following simple questions.!! What is a web application?!! Why we usually implement a C/S systems as a web application?!! What is a servlet?!! What is the difference of servlet and applet?!! What is the JSP?!! Why we usually prefer using JSP to coding servlet directly?!! Trace the behavior of calender.jsp line by line. 22