Page 1 of 1

About Question enthuware.jwpv6.2.870 :

Posted: Wed Jan 09, 2013 5:49 pm
by gurpreet_asrgndu
if the getRequestDispatcher method returns null , shouldnt the call to forward throw NullPointerException.

or does the NPE gets wrapped by ServletException ??

Re: About Question enthuware.jwpv6.2.870 :

Posted: Thu Jan 10, 2013 7:09 am
by admin
Irrespective of whether a NPE is thrown or a ServletException is thrown, they will be caught by the catch(Exception) block.

HTH,
Paul.

Re: About Question enthuware.jwpv6.2.870 :

Posted: Thu Jan 10, 2013 3:01 pm
by gurpreet_asrgndu
oh thanks Paul.

Re: About Question enthuware.jwpv6.2.870 :

Posted: Mon Mar 30, 2015 1:34 am
by GauravDaga
Ok, I understood the relative path URL but in order for it to work.. question should clearly tell the location of login.jst with respect to current servlet. It doesn't add up :(

Re: About Question enthuware.jwpv6.2.870 :

Posted: Mon Mar 30, 2015 1:39 am
by admin
There is no need to know the location of login.jsp. No matter where it is kept, an exception will be thrown.

Re: About Question enthuware.jwpv6.2.870 :

Posted: Wed Jul 12, 2017 11:02 am
by RumiJal
I understand that when using req.getRequestDispatcher("Login.jsp"); we get the ressource in a relative way. But relative to what exactly? The actual location is not mentioned and the request call is not clear so how we know that the last option is correct?

Re: About Question enthuware.jwpv6.2.870 :

Posted: Wed Jul 12, 2017 10:36 pm
by admin
Relative to the current request's path. For example, if the current request is handled by /myjsp/someview.jsp, then Login.jsp should be in /myjsp directory.

In this question, however, no matter where you keep Login.jsp, the code will not work because ServletContext's getRequestDispatcher expects an absolute path. It cannot understand relative path (i.e. path not starting with a / ).

HTH,
Paul.

Re: About Question enthuware.jwpv6.2.870 :

Posted: Thu Jul 20, 2017 12:38 am
by RumiJal
So when the servlet is invoked through the following url

http://localhost:8080/MyApp/

Then the answer is

It will compile and will work properly if //1 is replaced with: RequestDispatcher rd = req.getRequestDispatcher("Login.jsp");

But if the servlet is invoked through the following url for example

http://localhost:8080/MyApp/something/

the answer should be
It will compile but not work properly if //1 is replaced with: RequestDispatcher rd = req.getRequestDispatcher("Login.jsp");

Because the containter will try to find the Login.jsp in /MyApp/something/ directory. is that right?

Re: About Question enthuware.jwpv6.2.870 :

Posted: Thu Jul 20, 2017 8:26 am
by admin
That is correct.