About Question enthuware.jwpv6.2.786 :

Moderator: admin

Post Reply
dhanuddhara
Posts: 12
Joined: Fri Aug 15, 2014 10:16 am
Contact:

About Question enthuware.jwpv6.2.786 :

Post by dhanuddhara »

Could someone please explain me, what does expect by "Both calls are transparent to the browser."?
Does it means that the user can feel it is getting forward to another resource?

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

Re: About Question enthuware.jwpv6.2.786 :

Post by admin »

It means the browser has no knowledge that the server has forwarded the request to another resource. In other words, the user cannot feel that it is getting forwarded to another resources.
If you like our products and services, please help us by posting your review here.

renatumb
Posts: 47
Joined: Mon Apr 08, 2013 7:55 pm
Contact:

Re: About Question enthuware.jwpv6.2.786 :

Post by renatumb »

hi,

Could you give me a example of relative path and absolute path ?

I understand that I path started by "/" is relative. But if it is started for other thing, it is absolute.
So,

ServletContext.getRequestDispatcher("/...") -> Must start with "/", so it is a relative path

and

ServletRequest.getRequestDispatcher("/..." or "...") -> Absolute or relative path

But the explanation says:

The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) is that this method can take a relative path.

Wouldn't it be:
The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) is that this method can take a ABSOLUTE path.

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

Re: About Question enthuware.jwpv6.2.786 :

Post by admin »

No, the ServletRequest's getRequestDispatcher can take a relative path.

It sounds counter intuitive but a path that starts with / is actually an absolute path because it is interpreted to be from the context root. It is absolute because context root of a web app doesn't change. Thus, a path starting with / will always refer to the same resource no matter which servlet you try it from.

A path that does not start with a / is a relative path because it is interpreted to be relative to the servlet from which it is accessed. So if your path is say "a/b", it will mean "/a/b" if you try to resolve it from a default servlet but it will mean /x/a/b if you try to resolve it from a servlet attached to /x.

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

gupta.v21
Posts: 17
Joined: Wed Jan 07, 2015 11:33 pm
Contact:

Re: About Question enthuware.jwpv6.2.786 :

Post by gupta.v21 »

"ServletContext.getRequestDispatcher(String)" and "ServletRequest.getRequestDispatcher(String)"
I agree with both of your answers but 1st option should also be correct.

Both of the statements will return RequestDispatcher object do you wanna say.
Object obtained using "ServletContext.getRequestDispatcher(String)"
will be different from "ServletRequest.getRequestDispatcher(String)"

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

Re: About Question enthuware.jwpv6.2.786 :

Post by admin »

No, the question is talking about ServletContext.getRequestDispatcher(String) method and ServletRequest.getRequestDispatcher(String) method.
It is not talking about the return values of these method.

Option 1 is saying both methods are same. Explanation explains why they are different.

Can you replace a call to ServletContext.getRequestDispatcher(String) with ServletRequest.getRequestDispatcher(String) and still expect the code to always work as expected? Of course not (as explained in the explanation.). Thus, they are different and option 1 is incorrect.
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 19 guests