Servlets Advanced QuizS2C Home « Servlets Advanced Quiz

The questions in this Java Servlets quiz are on the topics covered in the Servlet Advanced section of the site. The table below lists the lessons, a description of the lesson content and the quiz question number range.

Lesson Summary

Click on a lesson in the table to go to that lesson for a refresher on the topics for that lesson.

Servlets Advanced Lessons Description Question Range
Lesson 1 - Context ListenersIn the first of three lessons on listeners we learn about context listeners.1 - 5
Lesson 2 - Request ListenersIn the second of three lessons on listeners we make a thorough investigation of request listeners.6 - 10
Lesson 3 - Session ListenersIn our third and final lesson on listeners we take an in-depth look at session listeners.11 - 17
Lesson 4 - Using FiltersIn this lesson we look at filters which are Java components that allow us to receive requests and responses and manipulate them through the filtering mechanism.18 - 24
Lesson 5 - WrappersThis lesson is all about decorating our requests and responses using wrappers.25 - 29
Lesson 6 - Declarative SecurityIn the first of two lessons on security we look at securing our web applications declaratively via the DD without having to change a single line of code.30 - 36
Lesson 7 - Programmatic SecurityIn the second of two lessons on security we look at securing our web applications programmatically.37 - 42

Servlets Quiz

The quiz below tests your knowledge of the material learnt in the Servlets Advanced section of the site.

Question 1 : Which listener would we use if we wanted to do something on application deployment?
- If we wanted to do something on application deployment we would use the <code>ServletContextListener</code> listener.
Question 2 : How are context listeners invoked?
- Listeners are invoked by the appropriate event type.
Question 3 : We need a servlet to action our context listeners?
- Context listeners can run before any servlet is loaded and don't require servlets for use.
Question 4 : How do we inform a web application of any context listeners we have implemented?
- We inform a web application of any context listeners we have implemented via the DD.
Question 5 : We need to inform the web container which kind of context listener is being used?
- There is no need to state which kind of listener is being used as the web container works this out using the Java Reflection API.
Question 6 : Which listener would we use if we wanted to do something on request scope initialisation?
- If we wanted to do something on request scope initialisation we would use the <code>ServletRequestListener</code> listener.
Question 7 : How are request listeners invoked?
- Listeners are invoked by the appropriate event type.
Question 8 : We need a servlet to action our request listeners?
- Request listeners can run before any servlet is loaded and don't require servlets for use.
Question 9 : How do we inform a web application of any request listeners we have implemented?
- We inform a web application of any request listeners we have implemented via the DD.
Question 10 : Which listener would we use to put processing in for when the request is going out of scope and we want to store some attribute in another scope?
- If we wanted to do something on request scope termination we would use the <code>requestDestroyed()</code> method of the <code>ServletRequestListener</code> listener.
Question 11 : Which listener would we use in a distributed environment for handling session migration?
- We would use the <code>HttpSessionActivationListener</code> listener in a distributed environment for handling session migration.
Question 12 : All session listeners are declared within the DD?
- The <code>HttpSessionActivationListener</code> and <code>HttpSessionBindingListener</code>listeners are NOT declared within the DD.
Question 13 : Do session bound objects in a distributed application need to implement anything?
- Session bound objects in a distributed application need to implement the <code>java.io.Serializable</code> interface.
Question 14 : Which event type is used with the HttpSessionAttributeListener listener?
- We use the <code>HttpSessionBindingEvent</code> event type with the <code>HttpSessionAttributeListener</code> listener.
Question 15 : Which of these listeners is not declared within the DD?
- The <code>HttpSessionBindingEvent</code> is not declared within the DD.
Question 16 : Which listener method gets invoked first?
- The <code>valueBound()</code> method of the <code>HttpSessionBindingListener</code> interface will always be invoked first.
Question 17 : Which listener method gets invoked last?
- The <code>valueUnbound()</code> method of the <code>HttpSessionBindingListener</code> interface will always be invoked last.
Question 18 : Filters are tied to a particular servlet?
- Filters are modular in nature and aren't tied to a particular servlet, in fact a servlet has no idea that the request or response is being filtered.
Question 19 : In which method are filtering tasks performed?
- Filtering tasks are performed in the <code>doFilter()</code> method.
Question 20 : How many filter lifecycle methods are there?
- There are three servlet lifecycle methods, these being <code>init()</code>, <code>doFilter()</code> and <code>destroy()</code>.
Question 21 : Which of these filter lifecycle stages comes first?
- The container has to instantiate a filter before we initialise it.
Question 22 : How many stages are there in the filter lifecycle?
- There are five stages in the filter lifecycle, these being class loading, instantiation, initialisation, servicing and destruction.
Question 23 : The FilterConfig object is passed as a parameter to which method?
- The <code>FilterConfig</code> object is passed as a parameter to the <code>init()</code> method.
Question 24 : What does the <dispatcher> sub-level element of the <filter-mapping> DD element default to?
- The <code>dispatcher</code> sub-level element of the <code>filter-mapping</code> DD element defaults to <code>REQUEST</code>.
Question 25 : Which design pattern do all the wrapper classes implement?
- All wrapper classes implement the Decorator design pattern.
Question 26 : What do all the wrapper implementations default to?
- All the wrapper implementations default to calling through to the wrapped request or response object.
Question 27 : What is a major benefit of using the wrapper implementations?
- A major benefit of using the wrapper implementations is that we only need to override the methods we want to change.
Question 28 : How do we inform a web application of any wrapper classes we have implemented?
- We inform a web application of any wrapper classes we have implemented programmatically.
Question 29 : We need to inform the web container which kind of wrapper implementation is being used?
- There is no need to state which kind of wrapper implementation is being used as we pass our custom request and/or response within our code.
Question 30 : Which part of security is generally achieved by sending the client a form where they have to fill in a username and password?
- Authentication is generally achieved by sending the client a form where they have to fill in a username and password.
Question 31 : Which is the only mandatory sub-level element of <security-constraint>?
- The only mandatory sub-level element of <code>security-constraint</code> is <code>web-resource-collection</code>.
Question 32 : Which of these authentication types does not use the <realm-name> sub-level element?
- The <code>FORM</code> authentication type does not use the <code>realm-name</code> sub-level element.
Question 33 : Which <security-constraint> sub-level element is used for data integrity and confidentiality?
- The <code>user-data-constraint</code> sub-level element of <code>security-constraint</code> is used for data integrity and confidentiality.
Question 34 : Which of these sub-level elements has to be specified in web-resource-collection?
- The <code>url-pattern</code> sub-level element of <code>web-resource-collection</code> has to be specifed at least once.
Question 35 : If no HTTP methods are specified in <web-resource-collection> what does this signify
- If no HTTP methods are specified in <code>web-resource-collection</code> method all HTTP methods that your servlet supports are constrained and can only be accessed by the roles specified in <code>auth-constraint</code>.
Question 36 : If the <auth-constraint> element is present and the <role-name> sub-level element is present and contains the special value * what does this signify?
- If the <code>auth-constraint</code> element is present and the <code>role-name</code> sub-level element is present and contains the special value <code>*</code> all users are allowed.
Question 37 : Which top-level element do we define FORM authentiacation in?
- We define FORM authentiacation in the <code>login-config</code> top-level element.
Question 38 : Which HTTP method must be used with FORM authentication?
- The HTML form used for the login page must use the POST HTTP method when using FORM authentication.
Question 39 : When using FORM authentication the action attribute of the form tag must be empty?
- When using FORM authentication the <code>sction</code> attribute of the <code>form</code> tag must contain the value <code>j_security_check</code>.
Question 40 : Which page must be included when using FORM authentication?
- When using FORM authentication both the error and login pages must be included.
Question 41 : Where must we place our login and error pages for FORM authentication?
- We must place our login and error pages for FORM authentication within the context root of the application.
Question 42 : When hard coding security within our servlets which method gives us finer grained control within the service methods that become available after authentication?
- The <code>isUserInRole()</code> method gives us finer grained control within the service methods that become available after authentication.
Quiz Progress Bar Please select an answer

What's Next?

That's the last of the servlets quizzes, the next quiz is on the JavaServer Pages section of the site.

go to home page Homepage go to top of page Top