Servlets Intermediate QuizS2C Home « Servlets Intermediate Quiz

The questions in this Java Servlets quiz are on the topics covered in the Servlet Intermediate 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 Intermediate Lessons Description Question Range
Lesson 1 - Using HTML FormsIn this lesson we learn how to create HTML forms, interrogate field values passed back to our servlets from HTML forms and how to action an appropriate response to form input.1 - 7
Lesson 2 - Session Management Part 1In the first of three lessons on conversational state we look at two ways to get around the statelessness of HTTP using URL rewriting and then look at the use of hidden fields.8 - 13
Lesson 3 - Session Management Part 2In our second lesson on session management we look at cookies, the first of two tracking techniques that are more flexible and work with web applications regardless of page volume.14 - 19
Lesson 4 - Session Management Part 3In our final lesson on session management we look at the HttpSession interface and how we can use objects of this type for session tracking.20 - 25
Lesson 5 - Attributes & ScopeIn this lesson we look at the different attributes and scopes available to our servlets.26 - 31
Lesson 6 - MultithreadingIn this lesson we discuss multithreading in web applications, whether a scope is thread safe, and if not, when and how we can protect resources within that scope from concurrent access.32 - 38
Lesson 7 - Redirects/Request DispatchingIn this lesson we learn about Redirects and Request Dispatching and how to use these mechanisms.39 - 45

Servlets Quiz

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

Question 1 : Which HttpServletRequest method will be delegated to from the service() method if the method attribute is left out of a HTML form?
- If the <code>method</code> attribute is left out of a HTML form then the browser will send a <code>GET</code> and so the <code>service()</code> will delegate to the <code>doGet()</code> method.
Question 2 : What will happen if the method attribute is left out of a HTML form and your servlet only contains a doPost() method?
- If the <code>method</code> attribute is left out of a HTML form then the browser will send a <code>GET</code> and so if you only have a <code>doPost()</code> method in your servlet an exception will occur.
Question 3 : The methods of which object are used to retrieve values entered on a HTML form?
- The methods of the <code>ServletRequest</code> object are used to retrieve values entered on a HTML form.
Question 4 : What will happen if the action attribute is left out of a HTML form that has been submitted?
- If the <code>action</code> attribute is left out of a HTML form the submitted form will be sent to the same URL used for the request.
Question 5 : If a path is specified in the action attribute what type of content can it point to?
- If a path is specified in the <code>action</code> attribute the path specified can point to either static or dynamic content.
Question 6 : What is sent to the server if the value of a HTML form input type of (text/hidden/password/textarea) is empty?
- If the value of a HTML form input type of (text/hidden/password/textarea) is empty then an empty string is sent to the server.
Question 7 : What is sent to the server if no value is selected for a select (single value) field?
- If no value is selected for a select (single value) field then the displayed option is sent to the server.
Question 8 : Which session management technique involves appending one or more tokens as a query string to a URL?
- URL rewriting is a session management technique which involves appending one or more tokens as a query string to a URL.
Question 9 : To use the hidden fields session management technique we need a HTML table element?
- To use the hidden fields session management technique we need a HTML form element so we can pass the hidden field(s) across to the server.
Question 10 : URL rewriting is not dependant upon storing information on the client's computer?
- The cookies session management technique is dependant upon storing information on the client's computer but URL rewriting is not.
Question 11 : When using URL rewriting any character can be passed across in the query string unchanged?
- The space character and the following special characters <code>; , / ? : @ & = + $ #</code> have to be encoded first, unless they are being used as delimiters.
Question 12 : Which is the better session management technique to use when we are passing across sensitive information to the server?
- URL rewriting passes information in the URL which is visible, whilst hidden fields pass information across within a form and so are better to carry sensitive information.
Question 13 : The URL rewriting and hidden fields session management techniques are suitable for web applications with what kind of page volume?
- The URL rewriting and hidden fields session management techniques are suitable for web applications with with low page volume.
Question 14 : Cookies are suitable for web applications with what kind of page volume?
- Cookies are suitable for web applications with any type of page volume.
Question 15 : Which method is used to delete cookies?
- The <code>setMaxAge()</code> method is used with the parameter value set to <code>0 </code> to delete cookies.
Question 16 : How are cookies transferred back to the server?
- Cookies get transferred back to the server in the request via the HTTP protocol.
Question 17 : What is the major disadvantage of cookies?
- The major disadvantage of cookies is that we are totally reliant on the user not disabling cookies in their browser settings.
Question 18 : Cookies only live as long as the session their created in?
- Cookies only live as long as the session their created in if no maximum age has been set, otherwise they live for the length of time specified using the <code>setMaxAge()</code> method.
Question 19 : We can access a cookie by name using the getCookie() method?
- The <code>getCookie()</code> method returns an array of cookies that we then have to loop over using the <code>getName()</code> method to check for the cookie name.
Question 20 : How many HttpSession objects can a client have?
- A client can have 0 or 1 <code>HttpSession</code> objects.
Question 21 : Values stored in a HttpSession object are not sent to the client?
- Values stored in a <code>HttpSession</code> object are not sent to the client but are retained in container memory. A unique session identifier is sent appended to the URL as a <code>jsessionid</code> parameter or a cookie is created called <code>JSESSIONID</code> containing the unique session identifier as its value.
Question 22 : The HttpSession object is always removed at the end of the session?
- If <code>setMaxInactiveInterval() </code> is passed <code>0 </code>, the <code>HttpSession </code> object will never expire and will remain on the <code>heap </code> until the application is unloaded or the servlet container is shut down.
Question 23 : How is session data stored for a HttpSession object?
- Session data stored for a <code>HttpSession</code> object is stored via attributes.
Question 24 : Objects added to a HttpSession should be from a class that implements java.io.Serializable ?
- Objects added to a <code>HttpSession</code> don't have to be implement <code>java.io.Serializable</code>, but if the container needs to serialize then we get an exception.
Question 25 : What type of session management can we use with HttpSession if cookies are disabled?
- If cookies are disabled we can encode our URLs using URL rewriting and get the unique session identifier using <code>HttpSession</code>.
Question 26 : Which is the narrowest scope?
- The narrowest scope is request scope.
Question 27 : When does request scope end?
- Request scope ends when a servlets <code>service()</code> method is popped off the stack.
Question 28 : A session ends when a user closes the browser?
- The session will persist and if that user then reopens the browser and goes back to the same web application a new session is started and the old session sits there using up resources.
Question 29 : Which is the broadest scope?
- The broadest scope is context scope.
Question 30 : Whenever a user vists a web application for the first time, a session is created?
- Sessions are not created automatically, we use the servlets <code>getSession()</code> method to create them.
Question 31 : There is no way to get a session object using the ServletRequest interface?
- There is no way to get a session object using the <code>ServletRequest</code> interface, because as far as the EE5 Servlets API is concerned sessions belong in the realm of HTTP only.
Question 32 : Which type of variables are thread safe?
- Local variables reside within a threads own stack and so are thread safe.
Question 33 : What do we synchronize on to protect session attributes from concurrent update?
- To protect session attributes from concurrent update we synchronize on the <code>HttpSession</code> object.
Question 34 : A client can only ever have one request thread running at a time?
- A client can open up new browser windows and call a servlet and each of these will also have a request thread.
Question 35 : Which type of attributes are most like to have concurrency issues?
- Context attributes have the broadest scope and therefore are most likely to have concurrency issues.
Question 36 : Concurrent access of context attributes can only occur when different clients access the same servlet within a web application?
- Concurrent access of context attributes can occur regardless of the servlet being used as all servlets within a web application have acesss to its context attributes.
Question 37 : What do we synchronize on to protect context attributes from concurrent update?
- To protect context attributes from concurrent update we synchronize on the <code>getServletContext()</code> method.
Question 38 : Which type of attributes are thread safe?
- Request attributes are thread safe as they are stored within the request object which comes into the <code>service()</code>and <code>doXXX()</code> methods as a method parameter, which it a type of local variable and hence will always reside its own stack.
Question 39 : Which technique passes control back to the server?
- A redirect will pass control back to the server.
Question 40 : What will happen if we do a sendRedirect() method after writing to the response?
- If we do a sendRedirect() method after writing to the response we get a <code>java.lang.IllegalStateException</code> exception.
Question 41 : We use a URL object for creating the URL to, when using the sendRedirect() method?
- We use a String object for creating the URL when using the <code>sendRedirect()</code> method.
Question 42 : We can use the sendRedirect() method for any kind of request?
- The <code>sendRedirect()</code> method is part of the <code>javax.servlet.http</code> package and so is not available for non-http requests.
Question 43 : Which request dispatch method passes temporary control to another resource?
- The <code>include()</code> request dispatch method passes temporary control to another resource.
Question 44 : Users see a new URL in the action bar when a request dispatch is used?
- Users see the same URL in the action bar when a request dispatch is used so are unaware of a different resource being used.
Question 45 : Which request dispatching type has to have a URL starting with a forward slash?
- When request dispatching using the <code>ServletContext()</code> type, the URL is relative to the container root and so has to start with a forward slash.
Quiz Progress Bar Please select an answer

What's Next?

The next quiz on Servlets is all about the lessons in the advanced servlets section.

go to home page Homepage go to top of page Top