Arjun V. Bala Page 20

Similar documents
Ch-03 Web Applications

Managing Data on the World Wide-Web

JSP. Common patterns

Servlet and JSP Filters

PA165 - Lab session - Web Presentation Layer

Java EE Introduction, Content. Component Architecture: Why and How Java EE: Enterprise Java

Creating A Walking Skeleton

CHAPTER 9: SERVLET AND JSP FILTERS

Aspects of using Hibernate with CaptainCasa Enterprise Client

Java Servlet Tutorial. Java Servlet Tutorial

CONTROLLING WEB APPLICATION BEHAVIOR WITH

Controlling Web Application Behavior

Piotr Nowicki's Homepage. Java EE 6 SCWCD Mock Exam. "Simplicity is the ultimate sophistication." Important!

Introduction to J2EE Web Technologies

Listeners se es. Filters and wrappers. Request dispatchers. Advanced Servlets and JSP

Visa Checkout September 2015

In this chapter the concept of Servlets, not the entire Servlet specification, is

Configure a SOAScheduler for a composite in SOA Suite 11g. By Robert Baumgartner, Senior Solution Architect ORACLE

Principles and Techniques of DBMS 5 Servlet

ACM Crossroads Student Magazine The ACM's First Electronic Publication

Web Container Components Servlet JSP Tag Libraries

Please send your comments to:

Supporting Multi-tenancy Applications with Java EE

Hello World Portlet Rendered with JSP for WebSphere Portal Version 4.1

IBM WebSphere Application Server

How To Understand The Architecture Of Java 2Ee, J2Ee, And J2E (Java) In A Wordpress Blog Post

Integration of Shibboleth and (Web) Applications

CSc31800: Internet Programming, CS-CCNY, Spring 2004 Jinzhong Niu May 9, Java Servlets

CHAPTER 5. Java Servlets

White Paper March 1, Integrating AR System with Single Sign-On (SSO) authentication systems

Java 2 Web Developer Certification Study Guide Natalie Levi

ANTAL Margit. Sapientia - EMTE, Pannon Forrás,,Egységes erdélyi felnőttképzés a

Java EE 6 New features in practice Part 3

Chapter 1. JOnAS and JMX, registering and manipulating MBeans

Pure server-side Web Applications with Java, JSP. Application Servers: the Essential Tool of Server-Side Programming. Install and Check Tomcat

Liferay Enterprise ecommerce. Adding ecommerce functionality to Liferay Reading Time: 10 minutes

Anders Møller & Michael I. Schwartzbach 2006 Addison-Wesley

SSO Plugin. HP Service Request Catalog. J System Solutions. Version 3.6

Servlet 3.0. Alexis Moussine-Pouchkine. mercredi 13 avril 2011

Creating Java EE Applications and Servlets with IntelliJ IDEA

Tomcat Servlet/JSP Reference Implementation

Web Applications. For live Java training, please see training courses at

JBoss Portlet Container. User Guide. Release 2.0

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

Web Application Programmer's Guide

CIS 455/555: Internet and Web Systems

Java Servlet 3.0. Rajiv Mordani Spec Lead

Class Focus: Web Applications that provide Dynamic Content

Workshop for WebLogic introduces new tools in support of Java EE 5.0 standards. The support for Java EE5 includes the following technologies:

Java Technologies. Lecture X. Valdas Rapševičius. Vilnius University Faculty of Mathematics and Informatics

Java Web Programming. Student Workbook

Performance Monitoring API for Java Enterprise Applications

Università degli Studi di Napoli Federico II. Corsi di Laurea Specialistica in Ingegneria Informatica ed Ingegneria delle Telecomunicazioni

Web Service Development Using CXF. - Praveen Kumar Jayaram

DTS Web Developers Guide

An introduction to web programming with Java

Web Application Architecture (based J2EE 1.4 Tutorial)

Trademarks: Yellowfin and the Yellowfin Logo are registered trademarks of Yellowfin International.

Software Design Document Securing Web Service with Proxy

Agenda. Summary of Previous Session. Application Servers G Session 3 - Main Theme Page-Based Application Servers (Part II)

Oracle Hyperion Financial Management Custom Pages Development Guide

Developing an EJB3 Application. on WebSphere 6.1. using RAD 7.5

Outline. CS 112 Introduction to Programming. Recap: HTML/CSS/Javascript. Admin. Outline

Programming on the Web(CSC309F) Tutorial: Servlets && Tomcat TA:Wael Aboelsaadat

In this chapter, we lay the foundation for all our further discussions. We start

Apache Shiro - Executive Summary

Oracle Hyperion Financial Management Developer and Customization Guide

How to program Java Card3.0 platforms?

Web Application Developer s Guide

Oracle WebLogic Server

CS108, Stanford Handout #33 Young. HW5 Web

2.8. Session management

<Insert Picture Here> Hudson Security Architecture. Winston Prakash. Click to edit Master subtitle style

Exam Prep. Sun Certified Web Component Developer (SCWCD) for J2EE Platform

Install guide for Websphere 7.0

Using weblock s Servlet Filters for Application-Level Security

BAPI. Business Application Programming Interface. Compiled by Y R Nagesh 1

Spring Security 3. rpafktl Pen source. intruders with this easy to follow practical guide. Secure your web applications against malicious

Java and Web. WebWork

SCCM 2012 Support Center Tool

2. Follow the installation directions and install the server on ccc

Web Applications. Originals of Slides and Source Code for Examples:

Encrypting*a*Windows*7*Hard*Disk* with%bitlocker%disk%encryption!

Model-View-Controller. and. Struts 2

XAP 10 Global HTTP Session Sharing

A detailed walk through a CAS authentication

The Server.xml File. Containers APPENDIX A. The Server Container

Mastering Tomcat Development

Intellicus Single Sign-on

JWIG Yet Another Framework for Maintainable and Secure Web Applications

Securing a Web Service

Red Hat JBoss Portal 5.1 Reference Guide

Transcription:

12) Explain Servlet life cycle & importance of context object. (May-13,Jan-13,Jun-12,Nov-11) Servlet Life Cycle: Servlets follow a three-phase life cycle, namely initialization, service, and destruction. Of the three phases, the initialization and destruction phases are performed only once while the service phase is carried out many times. The first phase of the servlet life cycle is initialization. It represents the creation and initialization of the resources the servlet may needed. All servlet must implement the javax.servlet.servlet interface, which defines the init() method that corresponds to the initialization phase of a servlet life cycle. As soon as a servlet is loaded in a container, the init() method is invoked before servicing any request. The second phase of the servlet life cycle is service phase. This phase of the servlet life cycle represents all the interactions carried out along with the requests that are handled by the servlet until it is destroyed. The service phase of the servlet life cycle is corresponds to the service() method of Servlet interface. The service() method is invoked once for every request. Then, its sole responsibility is to generate the response to that request. The service(0 method takes two objects as parameters, javax.servlet.servletrequest and javax.servlet.servletresponse. The destruction phase is the third and final phase of the servlet life cycle. This phase represents the termination of the servlet execution and its removal from the container. Destruction phase is corresponding to the destroy() method of the Servlet interface. To efficiently manage application resources, a servlet should properly use all the three methods of its life cycle. ServletContext: ServletContext object is used to get configuration information from Deployment Descriptor(web.xml) which will be available to any Servlet or JSPs that are part of the web application. Arjun V. Bala Page 20

There is one context per "web application" per Java Virtual Machine. The ServletContext object is contained within the ServletConfig object. That is, the ServletContext can be accessed using the ServletConfig object within a servlet. You can specify param-value pairs for ServletContext object in <context-param> tags in web.xml file. Example: <context-param> <param-name>facultyname</param-name> <param-value>arjunbala</param-value> </context-param> Diffrence between ServletContext & ServletConfig. Servlet Config Servlet Context Servlet config object represent single servlet It represent whole web application running on particular JVM and common for all the servlet Its like local parameter associated with Its like global parameter associated with whole particular servlet application It s a name value pair defined inside the servlet ServletContext has application wide scope so section of web.xml file so it has servlet wide define outside of servlet tag in web.xml file. scope getservletconfig() method is used to get the getservletcontext() method is used to get the config object context object. for example shopping cart of a user is a specific to particular user so here we can use servlet config To get the MIME type of a file or application session related information is stored using servlet context object. 13) Explain event handling in Java Servlet with example.(jan-13,jun-12) An event refers to a set of actions that may occur while an application is running. It could also be defined as a set of actions, such as clicking a button or pressing a key, performed by a user. The following list shows some of the events that may occur during the life cycle of a servlet: Initializing servlets. Adding, removing or replacing attributes in ServletContext. Creating, activating, passivating, or invalidating a Session. Adding, removing, or replacing attributes in a servlet session. Destroying servlets. Types of Servlet Events on the basis of their level of occurrence. Request level events o Refers to the events related to the client s information to a servlet. o There are two event listeners 1. ServletRequestListner 2. ServletRequestAttributeListner Servlet Context level events o Refer to the application level events o There are two event listeners 1. ServletContextListner 2. ServletContextAttributeListner Arjun V. Bala Page 21

Servlet Session level events o Refers to the events that are used to maintain the session of a client. o There are three event listeners 1. HttpSessionListner 2. HttpSessionAttributeListner 3. HttpSessionActivationListner Example: import javax.servlet.servletcontext; import javax.servlet.servletcontextevent; import javax.servlet.servletcontextlistener; ContextListner.java public class ContextListener implements ServletContextListener private ServletContext cont=null; public void contextinitialized(servletcontextevent evt) this.cont = evt.getservletcontext(); System.out.println("Context intialized...!!!!!"); JOptionPane.showMessageDialog(null,"Context intialized...!!!!!"); public void contextdestroyed(servletcontextevent evt) System.out.println("Context destroyed...!!!!!"); JOptionPane.showMessageDialog(null,"Context destroyed...!!!!!"); this.cont=null; web.xml <web-app> <listener> <listener-class>contextlistener</listener-class> </listener> <servlet> <servlet-name>demoservlet</servlet-name> <servlet-class>demoservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>demoservlet</servlet-name> <url-pattern>/demoservlet</url-pattern> </servlet-mapping> </web-app> Arjun V. Bala Page 22

14) Enlist and explain the need of filters with a program. (May-13,Jan-13,Jun-12) Need of Filters: Security verification Filters can be used for the security verification as a part of authentication process. Session validation Filters can be used for validating session for the application. Loggin operations Filters are required to keep the log of the operations taken place in the application. Internationalization It is used to implement the internationalization of the application. Triggering resource access events It is also used in the event handling procedure to trigger the events occurring for the resources. Image conversion & scaling maps Filters can be used for the image processing like conversing images in to large or small scale or scaling the map according to the users requirements. Data compression Filters needed to compress the data at the output so that the ultimate output will be of small in size. Encryption It is used to encrypt/decrypt the data, Filters are working at the end of the application so such operation can be useful for information security. Tokenization It can be used to tokenize the work, so that any one can use resources can be used with out worrying of dirty read/dirty write problem. Caching and XSL transformations of XML responses Filters are used to cache the data as well as transformation of XSL & XML. Debugging It can be used for debugging the application from the log file it has generated. Example: import java.io.ioexception; import java.io.printwriter; import javax.servlet.*; MyFilter.java public class MyFilter implements Filter public void init(filterconfig arg0) throws ServletException public void dofilter(servletrequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException PrintWriter out=resp.getwriter(); out.print("filter is invoked before"); chain.dofilter(req, resp);//sends request to next resource Arjun V. Bala Page 23

out.print("filter is invoked after"); public void destroy() web.xml <web-app> <servlet> <servlet-name>helloservlet</servlet-name> <servlet-class>helloservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>helloservlet</servlet-name> <url-pattern>/servlet1</url-pattern> </servlet-mapping> <filter> <filter-name>f1</filter-name> <filter-class>myfilter</filter-class> </filter> <filter-mapping> <filter-name>f1</filter-name> <url-pattern>/servlet1</url-pattern> </filter-mapping> </web-app> Arjun V. Bala Page 24