About Question enthuware.jwpv6.2.870 :

Moderator: admin

Post Reply
gurpreet_asrgndu
Posts: 55
Joined: Thu Jan 03, 2013 7:51 am
Contact:

About Question enthuware.jwpv6.2.870 :

Post by gurpreet_asrgndu » Wed Jan 09, 2013 5:49 pm

if the getRequestDispatcher method returns null , shouldnt the call to forward throw NullPointerException.

or does the NPE gets wrapped by ServletException ??

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

Re: About Question enthuware.jwpv6.2.870 :

Post by admin » Thu Jan 10, 2013 7:09 am

Irrespective of whether a NPE is thrown or a ServletException is thrown, they will be caught by the catch(Exception) block.

HTH,
Paul.

gurpreet_asrgndu
Posts: 55
Joined: Thu Jan 03, 2013 7:51 am
Contact:

Re: About Question enthuware.jwpv6.2.870 :

Post by gurpreet_asrgndu » Thu Jan 10, 2013 3:01 pm

oh thanks Paul.

GauravDaga
Posts: 1
Joined: Mon Mar 30, 2015 1:32 am
Contact:

Re: About Question enthuware.jwpv6.2.870 :

Post by GauravDaga » Mon Mar 30, 2015 1:34 am

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 :(

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

Re: About Question enthuware.jwpv6.2.870 :

Post by admin » Mon Mar 30, 2015 1:39 am

There is no need to know the location of login.jsp. No matter where it is kept, an exception will be thrown.

RumiJal
Posts: 9
Joined: Wed Jul 12, 2017 10:51 am
Contact:

Re: About Question enthuware.jwpv6.2.870 :

Post by RumiJal » Wed Jul 12, 2017 11:02 am

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?

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

Re: About Question enthuware.jwpv6.2.870 :

Post by admin » Wed Jul 12, 2017 10:36 pm

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.

RumiJal
Posts: 9
Joined: Wed Jul 12, 2017 10:51 am
Contact:

Re: About Question enthuware.jwpv6.2.870 :

Post by RumiJal » Thu Jul 20, 2017 12:38 am

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?

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

Re: About Question enthuware.jwpv6.2.870 :

Post by admin » Thu Jul 20, 2017 8:26 am

That is correct.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest