Web Application Basic Scopes Application Session Request Page 1.

Slides:



Advertisements
Similar presentations
Servlets & JSPs - Sharad Ballepu.
Advertisements

Dispatching, monitoring, filtering
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
Internet Technologies 1 Master of Information System Management Java Server Faces Model/View/Controller Design Pattern for Web Development Slides.
Configuring web servers and web applications 1. 2 Server configuration vs. application configuration A web server may run several web application Server.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
1 Listeners A listener is an event handler that the server invokes when certain events occur (e.g. web application initialization/shutdown, session created/timed.
/ department of mathematics and computer sciencedepartment of mathematics and computer science / architecture of information systems.
Session-02.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 8 Servlets (Based on Møller and Schwartzbach,
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
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.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
Chapter 5 Being a Web App. Very few servlet or JSP stands alone Many times in our application, different servlets or JSPs need to share information 
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
1 JSP with Custom Tags Blake Adams Introduction Advanced Java Server Pages – Custom Tags Keyterms: - Tag Library Descriptor(TLD) - Tag Libraries.
® IBM Software Group © 2007 IBM Corporation Servlet Listeners
Java Servlets Lec 27. Creating a Simple Web Application in Tomcat.
JSP Filters 23-Oct-15. JSP - FILTERS A filter is an object that can transform a request or modify a response. Filters are not servlets; they don't actually.
Chapter 9 Session Tracking. Session Tracking Basics Accessing the session object associated with the current request: Call request.getSession to get an.
J2EE Servlets Ch. 10 (Architecture) Ch. 12 (21 Days)
JSP Tag Libraries Lec Last Lecture Example We incorporated JavaBeans in “Course Outline” Example But still have to write java code inside java.jsp.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
CSC 2720 Building Web Applications Frameworks for Building Web Applications.
Chapter 11 Invoking Java Code with JSP Scripting Elements.
® IBM Software Group © 2007 IBM Corporation Servlet Filtering
SE-2840 Dr. Mark L. Hornick1 Servlet Threads and Sessions.
Servlet Filters JAVA Enterprise Edition. Servlet Filters Servlet Filters are Java classes that can be used in Servlet Programming for the following purposes:
Java Enterprise Edition Programming Page 1 of 9Configuring Servlets Web Application Context Name  In multiple web applications, a “context name” is used.
ORIGINAL BY WENDY LIU CURRENT API: Java Servlet and JSP 1.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
©SoftMoore ConsultingSlide 1 Filters. Filters can be used in a web application to intercept, examine, and possibly transform requests or responses associated.
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.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
J2EE T ECHNOLOGIES These are the technologies required to build large scale distributed applications, can be divided into – Component Technologies eg.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Chapter 4 Request and Response. Servlets are controlled by the container.
The Chain of Responsibility Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Expense Tracking System Developed by: Ardhita Maharindra Muskan Regmi Nir Gurung Sudeep Karki Tikaprem Gurung Date: December 05 th, 2008.
DEVELOPING WEB SERVICES WITH JAVA DESIGN WEB SERVICE ENDPOINT.
1 Lecture 8 George Koutsogiannakis/Summer 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
SDJ INFOSOFT PVT. LTD. 2 BROWSERBROWSER JSP JavaBean DB Req Res Application Layer Enterprise server/Data Sources.
Distributed Web Systems Cookies and Session Tracking Lecturer Department University.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
CS-4220 Dr. Mark L. Hornick1 Single class doing too many things =Bad Code Smell.
Servlets What is a Servlet?
CS3220 Web and Internet Programming Introduction to Java Servlets
ASP.NET Forms.
Event Handling Mimi Opkins CECS 493 Fall 2016.
Handling Errors in Web Applications
Servlet Sessions and Cookies
Java Servlets By: Tejashri Udavant..
JavaServer Pages (JSP)
Java Servlets.
Delegates and Events 14: Delegates and Events
Pre assessment Questions
JavaScript Functions.
Pre-assessment Questions
Servlet.
Knowledge Byte In this section, you will learn about:
Servlet API and Lifecycle
Server Side Programming: Java Servlets
Chapter 26 Servlets.
Knowledge Byte In this section, you will learn about:
CS3220 Web and Internet Programming Introduction to Java Servlets
Pre-assessment Questions
Presentation transcript:

Web Application Basic Scopes Application Session Request Page 1

Sessions … HttpSession session = request.getSession(); … session.getAttribute(String name) session.setAttribute(String name) session.removeAttribute(String name) Session.invalidate() Remember there are resources costs… 2

Controlling Session Timeouts Programmatically:  session.setMaxInactiveInterval(int seconds) Declaratively (web.xml) 180 Negative value means the session will never expire (watch out!). Same result if 0 is set declaratively. 3

Application-Wide Initialization Parameters web.xml element: context-param support- Read with the getInitParameter method of ServletContext (not ServletConfig which is used for servlet/jsp read of element) You may also use attributes for handling objects 4

5 Listeners A listener is an event handler that the server invokes when certain events occur (e.g. web application initialization/shutdown, session created/timed out…) In design pattern terms – observer pattern: An observer (in this case the listener) is notified when an event occurs in the subject(server). Typical uses:  Application-wide initialization routines  Managing dependencies between data stored in context or session attributes  Monitoring the running application (e.g. number of current sessions)

6 Listeners – Cont. There are different kinds of listener, each corresponding to an interface and a group of events. Some of them are: ServletContextListener  Web application initialized / shut down ServletRequestListener  request handler starting / finishing HttpSessionListener  session created / invalidated ServletContextAttributeListener  context attribute added / removed / replaced HttpSessionAttributeListener  session attribute added / removed / replaced

7 Listeners – Cont. To use a listener one simply implements the appropriate interface and registers the listener in the deployment descriptor. As an example, the following listener monitors the current and maximum number of active sessions.  This class implements both HttpSessionListener and ServletContextListener such that it is notified when the application starts, to initialize the context attributes, and when a session is created or invalidated.

8 Example: SessionMonitor (1/2) import javax.servlet.*; import javax.servlet.http.*; public class SessionMonitor implements HttpSessionListener, ServletContextListener { private int active = 0, max = 0; public void contextInitialized(ServletContextEvent sce) { store(sce.getServletContext()); } public void contextDestroyed(ServletContextEvent sce) {} public void sessionCreated(HttpSessionEvent se) { active++; if (active>max) max = active; store(se.getSession().getServletContext()); } Next Slide (Update Context Attributes)

9 Example: SessionMonitor (2/2) public void sessionDestroyed(HttpSessionEvent se) { active--; store(se.getSession().getServletContext()); } private void store(ServletContext c) { c.setAttribute("sessions_active", new Integer(active)); c.setAttribute("sessions_max", new Integer(max)); } Registration in web.xml : SessionMonitor Now that we have the class, what must we do? Context Attributes

Filters Code being executed before / after the servlet Can intercept and redirect processing  security  auditing Can modify requests and responses  data conversion (XSLT, gzip,...)  specialized caching – all without changing the existing servlet code! 10

11 Resources An Introduction to XML and Web Technologies / Anders Møller and Michael I. Schwartzbach – course literature Coreservlets.com