Java Enterprise Edition Programming Page 1 of 9Configuring Servlets Web Application Context Name  In multiple web applications, a “context name” is used.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

Internet i jego zastosowania 1 J2EE Servlets. Internet i jego zastosowania 2 Agenda Overview Servlet Interface Servlet Context Request Response Sample.
JSP and web applications
MC365 Application Servers: Servlets. Today We Will Cover: What a servlet is The HTTPServlet and some of its more important methods How to configure the.
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
JSP – Java Server Pages Part 1 Representation and Management of Data on the Internet.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
Configuring web servers and web applications 1. 2 Server configuration vs. application configuration A web server may run several web application Server.
1 Build a Web Application on J2EE. 2 J2EE Scenario Client – Web Server – EIS Resources Client – Web Server – EIS Resources Client – Application Server.
Objectives:1. Investigate the Web application deployment descriptor 2. Install and deploy Tomcat and struts 3. Design and deploy a struts application Struts.
Tomcat Configuration A Very, Very, Very Brief Overview.
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
Creating a.war file W(eb) AR(chive). Creating a.war file The following article may contain actual software programs in source code form. This source code.
Web Applications Basics. Introduction to Web Web features Clent/Server HTTP HyperText Markup Language URL addresses Web server - a computer program that.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 37 - JavaServer Pages (JSP): Bonus for Java Developers Outline 37.1 Introduction 37.2 JavaServer.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 8 Servlets (Based on Møller and Schwartzbach,
|Tecnologie Web L-A Anno Accademico Laboratorio di Tecnologie Web Sviluppo di applicazioni web Servlet
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
© Blackboard, Inc. All rights reserved. My First Building Block as a Content Type Heather Natour Senior Lead Engineer Blackboard Inc. July 18 th 1:30pm.
Apache Tomcat Representation and Management of Data on the Web.
Java Servlets CS-422. Application Mapping Your servlet application will be mapped to a directory structure: –“myapp” maps to some directory C:/docs/apps/myapp.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
AN OVERVIEW OF SERVLET TECHNOLOGY SERVER SETUP AND CONFIGURATION WEB APPLICATION STRUCTURE BASIC SERVLET EXAMPLE Java Servlets - Compiled By Nitin Pai.
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.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC.
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 
CS-4220 Dr. Mark L. Hornick1 Servlet configuration and deployment.
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.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
J2EE Overview Web Programming CSCI J2EE multi-tier architecture Servlet: Java class loaded into Web server JSP page: enhanced HTML page that is.
® IBM Software Group © 2007 IBM Corporation Servlet Listeners
Java Servlets & Java Server Pages Lecture July 2013.
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 7 Using Custom Tag Libraries and the JSP Standard Tag Library.
Java Server Pages (JSP)
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Servlet Filters JAVA Enterprise Edition. Servlet Filters Servlet Filters are Java classes that can be used in Servlet Programming for the following purposes:
JS (Java Servlets). Internet evolution [1] The internet Internet started of as a static content dispersal and delivery mechanism, where files residing.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
© 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.
Modern Programming Language. Web Container & Web Applications Web applications are server side applications The most essential requirement.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
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.
 2003 Prentice Hall, Inc. All rights reserved Deploying a Web Application ( may include.war )
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
DEVELOPING WEB SERVICES WITH JAVA DESIGN WEB SERVICE ENDPOINT.
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
1 Web Programming with Servlets & JSPs WEB APPLICATIONS – AN OVERVIEW.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
CS3220 Web and Internet Programming Introduction to Java Servlets
Handling Errors in Web Applications
Java Servlets By: Tejashri Udavant..
JavaServer Pages (JSP)
Pre-assessment Questions
Knowledge Byte In this section, you will learn about:
Servlet API and Lifecycle
CHAPTER 10 Servlet Programming
Objectives In this lesson you will learn about: Need for servlets
CS3220 Web and Internet Programming Introduction to Java Servlets
Introduction to Java Servlets
Directories and DDs 25-Apr-19.
Pre-assessment Questions
Presentation transcript:

Java Enterprise Edition Programming Page 1 of 9Configuring Servlets Web Application Context Name  In multiple web applications, a “context name” is used to access a specific Web application.  The general syntax of a servlet Web application URL is: e

Java Enterprise Edition Programming Page 2 of 9Configuring Servlets Accessing Servlet Using the Fully-Qualified Class  The problem in accessing servlet using the fully-qualified class is that the names can be very long.  It reveals the implementation details of about the Web application.  Example eb.ValidateUserServlet

Java Enterprise Edition Programming Page 3 of 9Configuring Servlets Servlet Mapping  In the deployment descriptor, servlet mapping is performed in two steps. 1. A servlet definition is configured which names a particular servlet and specifies the fully qualified Java technology class that implements that servlet. 2. A servlet mapping is created which identifies a URL structure that maps to the named servlet definition.

Java Enterprise Edition Programming Page 4 of 9Configuring Servlets Example of Deployment Descriptor <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" " app_2_3.dtd"> ADPROG1 Web Application Example This Web Application demonstrates a simple deployment descriptor. It also demonstrates a servlet definition and servlet mapping. </description Hello adprog1.web. HelloServlet Hello /greeting

Java Enterprise Edition Programming Page 5 of 9Configuring Servlets Deployment Environment  When a Web application is deployed to the Web container, the directory structure must follow a particular format:  The static HTML files are stored in the top level directory of the Web application.  The servlet and related Java technology class files must be stored in the WEB-INF/classes directory.  The auxiliary Java Archive (JAR) files must be stored in the WEB-INF/lib directory.  The deployment descriptor must be stored in the file called web.xml in the WEB-INF directory.

Java Enterprise Edition Programming Page 6 of 9Configuring Servlets Servlet Life Cycle Overview  The Web container manages the life cycle of a servlet instance by calling three methods defined in the Servlet interface: init, service and destroy.

Java Enterprise Edition Programming Page 7 of 9Configuring Servlets init Life Cycle Method  The init method is called by the Web container when the servlet instance is first created.  The Servlet specification guarantees that no requests will be processed by this servlet until the init method has completed.

Java Enterprise Edition Programming Page 8 of 9Configuring Servlets service and destroy Life Cycle Method  The service method is called by the Web container to process a user request.  The destroy method is called by the Web container when the servlet instance is being destroyed.  The Servlet specification guarantees that all requests will be completely processed before the destroy method is called.

Java Enterprise Edition Programming Page 9 of 9Configuring Servlets Servlet Configuration  When a servlet is initialized, a common task is to load any external resources into memory.  The Web container uses a configuration object to pass the initialization parameters to the servlet at runtime.

Java Enterprise Edition Programming Page 10 of 9Configuring Servlets ServletConfig API

Java Enterprise Edition Programming Page 11 of 9Configuring Servlets Initialization Parameters  Servlet initialization parameters are name-value pairs that are declared in the deployment descriptor. The names and values are arbitrary strings.  Example: MsgHello1 adprog1.web.HelloServlet msgText Hello msgText Hello

Java Enterprise Edition Programming Page 12 of 9Configuring Servlets ServletContext Object  A Web application is a self-contained collection of static and dynamic resources: HTML pages, media files, data and resource files, servlets (and JSP pages), and other auxiliary Java technology classes and objects.  A ServletContext object is the runtime representation of the Web application.

Java Enterprise Edition Programming Page 13 of 9Configuring Servlets ServletContext API  Read-only access to application scoped initialization parameters  Read-only access to application-level file resources  Read-write access to application scoped attributes  Logging functionality

Java Enterprise Edition Programming Page 14 of 9Configuring Servlets ServletContext API

Java Enterprise Edition Programming Page 15 of 9Configuring Servlets Context Initialization Parameters  A Web application may have one or more initialization parameters.  Context initialization parameters are accessed using the getInitParameter method on the ServletContext object.  The context-param element tag is used to configure the parameters in the deployment descriptor.

Java Enterprise Edition Programming Page 16 of 9Configuring Servlets Example catalogFileName /WEB- INF/catalog.txt</param-value

Java Enterprise Edition Programming Page 17 of 9Configuring Servlets Retrieving Context Parameters  To retrieving a context initialization parameter, invoke the getInitParameter() method from the ServletContext instance. ServletContext context = sce.getServletContext() String catalogFileName = context.getInitParameter(“catal ogFileName”);

Java Enterprise Edition Programming Page 18 of 9Configuring Servlets Access to File Resources  The ServletContext object provides read- only access to file resources through the getResourceAsStream() method that returns a raw InputStream object.  Example ServletContext context = sce.getServletContext(); String catalogFileName = context.getInitParameter(“catal ogFileName”); InputStream is = null; BufferedReader catReader = null; try{ is = context.getResourceAsStream(cat alogFileName); catReader = new BufferedReader(new InputStreamReader(is));

Java Enterprise Edition Programming Page 19 of 9Configuring Servlets Writing to the Web Application Log File  The ServletContext object provides write- only access to log file:  The log(String) method writes a message to the log file.  The log(String, Throwable) method writes a message and the stack trace of the exception or error to the log file.  Example context.log(“The ProductList has been initialized.”);

Java Enterprise Edition Programming Page 20 of 9Configuring Servlets Accessing Shared Runtime Attributes  The ServletContext object provides read- write access to attributes shared across all servlets through the getAttribute and setAttribute methods.  Storing an Application Scoped Attribute context.setAttribute(“catalog”,ca talog);  Retrieving an Application Scoped Attribute ServletContext context = (ProductList) context.getAttribute(“catalog”) ;

Java Enterprise Edition Programming Page 21 of 9Configuring Servlets Web Application Life Cycle  When the Web container is started, each Web application is initialized. When the Web container is shut down, each Web application is destroyed.

Java Enterprise Edition Programming Page 22 of 9Configuring Servlets ServletContextListener API