What is a Servlet? Java Program that runs in a Java web server and conforms to the servlet api. A program that uses class library that decodes and encodes.

Slides:



Advertisements
Similar presentations
7 Copyright © 2005, Oracle. All rights reserved. Maintaining State in J2EE Applications.
Advertisements

Message Forwarding Semi-automatic proxy delegation.
Technology Overview JAVA Servlets CS-611 S. Witherspoon.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 42 Web Services.
Fundamentals, Design, and Implementation, 9/e Chapter 14 JDBC, Java Server Pages, and MySQL.
Servlets and a little bit of Web Services Russell Beale.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
JSP Java Server Pages Reference:
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.
CGI Programming Languages Web Based Software Development July 21, 2005 Song, JaeHa.
1 Guide to JSP common functions 1.Including the libraries as per a Java class, e.g. not having to refer to java.util.Date 2.Accessing & using external.
Struts 2.0 an Overview ( )
UNIT-V The MVC architecture and Struts Framework.
ASHIMA KALRA.  INTRODUCTION TO JSP INTRODUCTION TO JSP  IMPLICIT OBJECTS IMPLICIT OBJECTS  COOKIES COOKIES.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
|Tecnologie Web L-A Anno Accademico Laboratorio di Tecnologie Web Sviluppo di applicazioni web Servlet
1 Servlet How can a HTML page, displayed using a browser, cause a program on a server to be executed?
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
JavaScript, Fourth Edition
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
JSP Java Server Pages Softsmith Infotech.
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
Standalone Java Application vs. Java Web Application
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
USING PERL FOR CGI PROGRAMMING
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Session Tracking - 2 Lec 32. Last Lecture Review  Session Tracking – why?  Need to store state – typical solutions Cookies – already learned URL Rewriting.
Webcommerce Computer Networks Webcommerce by Linnea Reppa Douglas Martindale Lev Shalevich.
Web Pages with Features. Features on Web Pages Interactive Pages –Shows current date, get server’s IP, interactive quizzes Processing Forms –Serach a.
Web Application Development * These slides have been adapted and modified from CoreServlets course material (Marty Hall) and LUMS cs391 (Umair Javed).
Java Servlets & Java Server Pages Lecture July 2013.
Chapter 6 Server-side Programming: Java Servlets
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Session Management.
CSCI 6962: Server-side Design and Programming Java Server Faces Scoping and Session Handling.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
ASP (Active Server Pages) by Bülent & Resul. Presentation Outline Introduction What is an ASP file? How does ASP work? What can ASP do? Differences Between.
Saving State on the WWW. The Issue  Connections on the WWW are stateless  Every time a link is followed is like the first time to the server — it has.
Java Servlets and Java Server Pages Norman White Stern School of Business.
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.
21/12/20151 T h i s p r e s e n t a t i o n w i l l p r o b a b l y i n v o l v e a u d i e n c e d i s c u s s i o n, w h i c h w i l l c r e a t e a.
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.
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
©SoftMooreSlide 1 Session Tracking with Servlets.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 21 Java Servlets Wed. 11/22/00 based on material.
Java Servlets and Java Server Pages
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Java Server Pages. 2 Servlets The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
8-Mar-16 More About Servlets Session Tracking. Persistent information A server site typically needs to maintain two kinds of persistent (remembered) information:
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
2 Copyright © 2006, Oracle. All rights reserved. Running a Forms Developer Application.
Managing State Chapter 13.
Running a Forms Developer Application
Servlets.
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
Java Servlets By: Tejashri Udavant..
Lecture: Protocols in Detail
Java Servlets.
Pre assessment Questions
Chapter 6 Server-side Programming: Java Servlets
Handling State in Web Applications
Objectives In this lesson you will learn about: Need for servlets
Chapter 42 Web Services.
Presentation transcript:

What is a Servlet? Java Program that runs in a Java web server and conforms to the servlet api. A program that uses class library that decodes and encodes http data.

What is HTTP data? Queries (get http 1.1 file name) Responses (i.e., html output to a printer made from a socket output stream). A web server does this! Webservers manage the http query and synthesize a response.

What kind of features can I get from the servlet API? Object oriented interface to the http servlet requests and responses. A nice way to parse input parameters from forms written in html. State management.

What is state management? State management enables the implementation of a finite state machine that is associate with a session. Http is inherently without memory. So how do store the state without memory?

Client-side state management Store data in the browser (client). Cookies are sometimes enabled for storing data in the browser. Cookies are limited

Whats a cookie? Data stored by client tranmitted as a part of the http stream from web server. Limits of a cookie: –Size (20 kB) per cookie –Number (20 cookies per domain) Not all browsers accept cookies Security can be a problem….

Cookies have a life! You can set the expiration date. You can delete your old cookies You can upload other peoples cookies!

What is the alternative to cookies? I need to have state management! URL Rewriting can help here! – ri328urh32iuh –The junk at the end is a UUEncoded symbol that uniquely identifies the URL. –This encodes the session!

What do we do? Cookies URL rewriting –Visibly alters the URL and makes it impossible to bookmark. HttpSession enable automatic changeover from URL rewriting to Cookies, so you don’t have to decide!

A good feature! HttpSession class –Enable session management –Automatically change over from cookies to url rewriting, when required. –Give an object oriented interface to session management –Allows me to pretend to write Serializble objects to the client.

Why do I need a servlet API Using sockets you can build http processor! You don’t! But it makes it easier! Why? –Because of Services and features that are provided

Servlet Dispatch How do we dispatch?

What is dispatch? Multi-way change in the flow of control. If (bexp1) statement Else if (bexp2) statement2 Switch(int, char, short,) // very efficient but very limited

What is limited about switch? Can’t switch on a reference data type (i.e, string).

What use switch with a string? Parsers Servlet dispatch, which takes a command

How can a switch with string? Associate the string with a number. String s[] = {“s1”, “s2”,…}; S[0] = “s1”. The numbers correspond to tokens. So use a HashMap.

What’s so great about a hashMap? Fast! O(constant). Cost – space! Trading space for time!!!!

How fast is the if-else clause is? If (bexp1) statement1 O(N) where N is the number of string.

Another way to dispatch.. Reflection How fast is reflection? O(C) because a hash map is used to map the string into a method. It has no type safety! No compile time checking!

How do I build a parser based reflection system? Use a class name and instance the class then invoke some methods. –Bad because you are making new instances dynamically and that takes both speed and time. Use a an existing instance (singleton pattern) and invoke a method on that! –Use the command to map to a method –Request and response are the args.

DispatchProcessorClass Class DispatchProcessor { –doLogin(Request, Response) –doLogOut(Request, Response) –doCommand(String, Request, Response) Use reflection to map the String into a doCommand }

DispatchHub Servlet Single Entrypoint into the system Responsible to making sure that you have access. Message forwards to dispatch processor.

What is the alternative? Class dispatchHub…{ –doGet(request, response) { String command c =… If (c.equals(doLogin)) doLogin(…) Else (c.equals(doLogout)) doLogout(…) Else (c.equals….) –} }

I like if-else Compile-time check Type safe Reliable Not too slow for small numbers of strings. Hard to maintain.

What is wrong with if-else? To add a command: –1. expand the if-else clause by 1 string. –2. You have to add a method for the command –3. You have to add a command to you form –You have to be consistent in 3 places.

What is so good about a reflection based dispatch? –1. Place a command the form –2. Place a method in the dispatch processor. Not type save No run-time check A little slower?

Why not use the Command Pattern? New commandString(String s) { –Public void run() { Statements here…… –} };

How string dispatcher? Sd.add(new CommandString(“doLogin”){ –Public void run() { DispatchProcessong.doLogin(request, response); –} }); Sd.execute(“doLogin”);

Key Advantage Key in the HashMap is of any string that is unique. Not possible with reflection. -> “doLogin”.

Moving classes is hard! examples.stringswitch.SwitchTest Could be moved to Utils or Junit If class names reside in a xml file or a HTML file, then these must be changed too!

CR320 Final 1. Select a jar file in a directory 2. List the classes in the jar files that implement the Computable interface 3. Require the user to select one of those classes 4. Use the ByteCodeClassLoader to deploy the class to a compute server

Final…Continued.. Invoke the compute method remotely and return the result.