Pre assessment Questions

Slides:



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

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 10 Servlets and Java Server Pages.
6 Copyright © 2005, Oracle. All rights reserved. Using Advanced Techniques in Servlets.
Learning the Basics – Lesson 1
1 Servlets Based on Notes by Dave Hollinger & Ethan Cerami Also, the Online Java Tutorial by Sun.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Java Programming, 3e Concepts and Techniques Chapter 4 Decision Making and Repetition with Reusable Objects.
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
1 Chapter 12 Working With Access 2000 on the Internet.
Servlets and a little bit of Web Services Russell Beale.
An introduction to Java Servlet Programming
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
Java Servlets. What Are Servlets? Basically, a java program that runs on the server Basically, a java program that runs on the server Creates dynamic.
Servlets Pranav Maydeo. What is a Servlet ? Servlets are modules of Java code that run in a server application to answer client requests. Servlets are.
Software Architecture for ColdFusion Developers Unit 4: Application Events and Global Variables.
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.
Microsoft Internet Information Services 5.0 (IIS) By: Edik Magardomyan Fozi Abdurhman Bassem Albaiady Vince Serobyan.
Li Tak Sing COMPS311F. Static attributes in Servlets Since Servlets are also Java classes, you can also use static attributes to store values that can.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
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 6 Server-side Programming: Java Servlets
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Session Management.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
CSC 2720 Building Web Applications Frameworks for Building Web Applications.
XP Tutorial 8 Adding Interactivity with ActionScript.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
® IBM Software Group © 2007 IBM Corporation Servlet Filtering
Li Tak Sing COMPS311F. A web page that counts the number of times that you have visited the page. You can try the page at:
Servlet Filters import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class TimerFilter implements Filter { /* J2EE v1.3 Filter.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
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.
Servlet Filters JAVA Enterprise Edition. Servlet Filters Servlet Filters are Java classes that can be used in Servlet Programming for the following purposes:
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
© 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.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
The Chain of Responsibility Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Securing Web Applications Lesson 4B / Slide 1 of 34 J2EE Web Components Pre-assessment Questions 1. Identify the correct return type returned by the doStartTag()
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
Speaker Name Speaker Title Speaker Title Oracle Corporation Olivier Le Diouris Principal Product Manager Oracle Corporation Building Servlet and JSP Applications.
Microsoft FrontPage 2003 Illustrated Complete Creating a Web Site.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Computing with C# and the .NET Framework
Creating Oracle Business Intelligence Interactive Dashboards
Working in the Forms Developer Environment
Handling Errors in Web Applications
Web Programming Developing Web Applications including Servlets, and Web Services using NetBeans 6.5 with GlassFish.V3.
Java Servlets By: Tejashri Udavant..
Learning the Basics – Lesson 1
Java Servlets.
Chapter 6 Server-side Programming: Java Servlets
Pre-assessment Questions
Pre-assessment Questions
Knowledge Byte In this section, you will learn about:
Pre-assessment Questions
Exploring Microsoft® Access® 2016 Series Editor Mary Anne Poatsy
Chapter 26 Servlets.
Introduction to Servlets
Objectives In this lesson you will learn about: Need for servlets
Knowledge Byte In this section, you will learn about:
Pre-assessment Questions
Objectives In this lesson, you will learn about:
PHP-II.
Presentation transcript:

Pre assessment Questions Identify the correct statement. a) Cookies are created on the server and stored by the browser on the client machine. b) Cookies are created and stored on the server. c) Cookies are created by the browser and stored by the server on the client machine. d) Cookies are created and stored by the browser on the client machine. J2EE Web Components

Pre-assessment Questions (Contd.) The setMaxAge(int expiry) method defined in the Cookie class sets: a) The maximum age of cookies in milliseconds b) The maximum age of cookies in seconds c) The maximum age of cookies in minutes d) The maximum age of cookies in hours J2EE Web Components

Pre assessment Questions (Contd.) The setMaxInactiveInterval(int interval) method of the HttpSession interface sets: a) The maximum age of the session in seconds. b) The maximum age of the session in milliseconds. c) The maximum time for which a client can remain inactive before the session is invalidated in seconds. d) The maximum time for which a client can remain inactive before the session is invalidated in milliseconds. Which HttpServletResponse field represents 200 status code? a) SC_OK b) SC_ACCEPTED c) SC_CONTINUE d) SC_SWITCHING_PROTOCOLS J2EE Web Components

Pre assessment Questions (Contd.) Identify the correct statement. a) The setStatus()method throws IllegalStateExcetion when it is invoked. b) The setStatus()method throws IllegalStateExcetion if it is called before the response is committed. c) The setStatus()method throws IllegalStateExcetion if it is called after the response is committed. d) The setStatus()method never throws IllegalStateExcetion. J2EE Web Components

Solutions to Pre-assessment Questions 1. a. Cookies are created by the server and stored by the browser on the client machine. 2. b. The maximum age of cookies in seconds 3. c. The maximum time for which a client can remain inactive before the session is invalidated in seconds. 4. a. SC_OK 5. c. The setStatus()method throws IllegalStateExcetion if it is called after the response is committed. J2EE Web Components

Objectives In this lesson you will learn about: Inter-servlet communication Single-threaded and multi-threaded servlets Using servlet filters to modify the request and response objects J2EE Web Components

Inter-Servlet Communication A process where two or more servlets communicates with each other to process the client request. A servlet can forward the request to another servlet to process the client request. A servlet can include the output of another servlet to process the client request. J2EE Web Components

Inter-Servlet Communication (Contd.) Inter-servlet communication using Request Dispatcher A Request Dispatcher: Is an object of the javax.servlet.RequestDispatcher interface that allows inter-servlet communication. Object is used to include the content of another servlet. Object is used to forward the request to another servlet. J2EE Web Components

Inter-Servlet Communication (Contd.) Inter-servlet communication using the Request Object Stores the calculated data as attribute to the request object in the first servlet. Forwards the request to the second servlet using the RequestDispatcher. Retrieves the data from the request object and displays the result using the second servlet. J2EE Web Components

Demonstration-Creating a Customized Error Page Problem Statement InfoSuper Inc. has created a dynamic Web site. Whenever an error occurs, the stack trace displayed in the browser is difficult to understand. David Wong, the system analyst of the company asks Don Allen, the software programmer of the company to create a customized error page. Whenever an exception is thrown by a servlet, the servlet dispatches the request to the customized error page. The error page then displays the error in the browser in a more understandable format. J2EE Web Components

Demonstration-Creating a Customized Error Page (Contd.) Solution Create a servlet that throws an exception and stores the Exception object as an attribute to the request object. The servlet then forwards the request object to an error page. Create a servlet that acts as a custom error page to display the error message. Compile and deploy the servlets. Run the program. J2EE Web Components

Servlet Threading Model The two types of Servlet Threading Model are: Multi-threaded Model Single-threaded Model J2EE Web Components

Servlet Threading Model (Contd.) Developing Thread-Safe Servlets While developing servlets in a multi-threaded model, threading issues needs to be handled to protect the shared resource. Therefore, we need to identify the types of attributes that are inherently thread-safe and the types that need to be guarded for thread safety. J2EE Web Components

Servlet Threading Model (Contd.) Developing Thread-Safe Servlets (Contd.) The Various thread-safe capabilities of attributes, methods, and fields in a servlet are: init() and destroy() methods local variables Request attributes Context attributes Data stored in session attributes The two approaches that can be followed for developing thread-safe servlets are: Synchronizing block of codes for accessing a shared resource Synchronizing methods for accessing a shared resource J2EE Web Components

Servlet Filters Servlet filters: Are objects that intercept the requests and response that flow between a client and a servlet. Modify the headers and content of a request coming from a Web client and forward it to the target servlet. Intercept and manipulate the headers and contents of the response that the servlet sends back. J2EE Web Components

Servlet Filters (Contd.) The advantages of using servlet filters are: You can identify the type of request coming from the Web client, such as HTTP and FTP, and invoke the servlet that needs to process the request. You can validate a client using servlet filters before the client accesses the servlet. You can retrieve the user information from the request parameters to authenticate the user. You can use servlet filters to identify the information about the MIME types and other header contents of the request. J2EE Web Components

Servlet Filters (Contd.) Advantages of using servlet filters are (Contd.): You can use servlet filters to facilitate a servlet to communicate with the external resources. You can use servlet filters to intercept responses and compress it before sending the response to the client. J2EE Web Components

Servlet Filters (Contd.) Programming of filters include: Creating Filters Deploying Servlet Filters J2EE Web Components

Servlet Filters (Contd.) Creating Filters The following code snippet shows a filter which calculates the time taken by a servlet to process the client request: public class ProcessingTimeFilter implements Filter { public void do Filter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { long service_Start = System.currentTimeMillis(); chain.doFilter(request, response); long service_Stop = System.currentTimeMillis(); long serviceTime = (service_Stop - service_Start); flt_cnfg.getServletContext().log("Time taken to process request is: “ + serviceTime + " milliseconds"); }} Deploying Filters J2EE Web Components

Servlet Filters (Contd.) Deploying Filters include: Adding a filter to the Web application Mapping the filter to the Web application J2EE Web Components

Servlet Filters (Contd.) Adding the filter to Web application involves: Add the filter to the Web application in the similar way as you add a servlet to a Web application using the deploytool. J2EE Web Components

Servlet Filters (Contd.) Select the component type as No Component in the New Web Application Wizard - Choose Component Type dialog box of the New Web Application Wizard as shown in the following figure: J2EE Web Components

Servlet Filters (Contd.) Mapping the filter to Web application involves: Select the Web application to which you have added the filter class in the J2EE Deploytool window. J2EE Web Components

Servlet Filters (Contd.) Click the Filter Mapping tab in the right pane of the J2EE Deploytool window to display the Filter Mapping tabbed page, as shown in the following figure: J2EE Web Components

Servlet Filters (Contd.) Click the Edit Filter List button to display the Servlet Filters for WebApp dialog box. Click the Add Filter button in the Servlet Filter for WebApp dialog box. Select ProcessingTimeFilter from the drop-down list of the Filter Class column. Specify the name of the filter in the Filter Name column, as shown in the following figure: J2EE Web Components

Servlet Filters (Contd.) Click the OK button to return to the Filter Mapping tabbed page in the J2EE Deploytool window. J2EE Web Components

Servlet Filters (Contd.) Click the Add button under the Filter Mapping tabbed page to display the Add Servlet Filter Mapping dialog box. Select ProcessingTimeFilter from the Filter Name drop-down list. In the Filter Target pane, select the Filter Servlets that match this URL Pattern option and specify /* in the URL Pattern text box. This specifies that the filter needs to intercept all requests and response coming to this Web application. The following figure shows the Add Servlet Filter Mapping dialog box: J2EE Web Components

Servlet Filters (Contd.) Click the OK button to complete the filter mapping process. J2EE Web Components

Summary In this lesson, you learned: Forwarding requests to other servlets using the forward() method of RequestDispatcher. Including the content of other servlets in a servlet using the include() method of RequestDispatcher. Performing inter-servlet communication using RequestDispatcher and servlet request object. Multi-threaded servlet model is the default threading model of a servlet. Various functions of a servlet filter are: Identifying the type of client browser. Identifying the character encoding used by the client browser. J2EE Web Components

Summary (Contd.) Developing servlet filters using Filter interface, FilterConfig interface, ServletRequest interface, and ServletResponse interface. Adding filter to a Web application and mapping them to a servlet to filter the contents of a servlet. J2EE Web Components