About Question enthuware.jwpv6.2.747 :

Moderator: admin

Post Reply
grendel777@o2.pl
Posts: 4
Joined: Mon Jan 11, 2016 1:52 pm
Contact:

About Question enthuware.jwpv6.2.747 :

Post by grendel777@o2.pl »

What if different protocol request (not HTTP) is made to url mapped to HttpServlet?

Will option "For any and every request, at least 1 of its methods will be called." be incorrect?

admin
Site Admin
Posts: 8853
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.747 :

Post by admin »

Unless specified in the question, or unless the question is clearly about the protocols, you have to consider HTTP only.

But to answer your question, I am not sure how you can map a protocol to a servlet. A protocol is implemented by the web server, which interprets the incoming request and invokes appropriate handler. For example, if an HTTP request goes to Tomcat server, it will interpret the request and forward it to appropriate servlet. If you send a non-http request to Tomcat, it will not understand the request and there is no question of the request reaching the servlet.
If you like our products and services, please help us by posting your review here.

grendel777@o2.pl
Posts: 4
Joined: Mon Jan 11, 2016 1:52 pm
Contact:

Re: About Question enthuware.jwpv6.2.747 :

Post by grendel777@o2.pl »

For sure I agree it would be a problem with any server available.
Yet, regarding spec itself, GenericServlet was intended to be protocol independent.

admin
Site Admin
Posts: 8853
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.747 :

Post by admin »

GenericServlet, yes, it can be used for any protocol. But HttpServlet, No. HttpServlet is meant for HTTP only.
If you like our products and services, please help us by posting your review here.

himaiMinh
Posts: 358
Joined: Fri Nov 29, 2013 8:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.747 :

Post by himaiMinh »

Hi,
the explanation says when the first request is made to a servlet, the init() method is called.
By according to Chapter 2.3.2 of Serlvet 3.0 specification, init() method is called before the servlet handles any request.
So, I think regardless there is a first request or not, the init() method is always called after the serlvet has been instantiated.

admin
Site Admin
Posts: 8853
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.jwpv6.2.747 :

Post by admin »

But a container may not even initialize a servlet if there is no request. You can only state for certain that it will be called before the first request is processed by the servlet.

This question clearly specifies, "Assuming that it is not preloaded or preinitialized,....", therefore the explanation is correct.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests