Page 1 of 1

About Question enthuware.jwpv6.2.786 :

Posted: Fri Sep 12, 2014 9:44 am
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?

Re: About Question enthuware.jwpv6.2.786 :

Posted: Fri Sep 12, 2014 11:04 am
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.

Re: About Question enthuware.jwpv6.2.786 :

Posted: Tue Dec 01, 2015 4:54 pm
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.

Re: About Question enthuware.jwpv6.2.786 :

Posted: Wed Dec 02, 2015 8:54 pm
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.

Re: About Question enthuware.jwpv6.2.786 :

Posted: Thu Apr 14, 2016 10:45 am
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)"

Re: About Question enthuware.jwpv6.2.786 :

Posted: Thu Apr 14, 2016 9:44 pm
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.