All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: About Question enthuware.jwpv6.2.870 :
PostPosted: Wed Jan 09, 2013 5:49 pm 
Offline

Joined: Thu Jan 03, 2013 7:51 am
Posts: 55
if the getRequestDispatcher method returns null , shouldnt the call to forward throw NullPointerException.

or does the NPE gets wrapped by ServletException ??


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.870 :
PostPosted: Thu Jan 10, 2013 7:09 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6602
Irrespective of whether a NPE is thrown or a ServletException is thrown, they will be caught by the catch(Exception) block.

HTH,
Paul.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.870 :
PostPosted: Thu Jan 10, 2013 3:01 pm 
Offline

Joined: Thu Jan 03, 2013 7:51 am
Posts: 55
oh thanks Paul.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.870 :
PostPosted: Mon Mar 30, 2015 1:34 am 
Offline

Joined: Mon Mar 30, 2015 1:32 am
Posts: 1
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 :(


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.870 :
PostPosted: Mon Mar 30, 2015 1:39 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6602
There is no need to know the location of login.jsp. No matter where it is kept, an exception will be thrown.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.870 :
PostPosted: Wed Jul 12, 2017 11:02 am 
Offline

Joined: Wed Jul 12, 2017 10:51 am
Posts: 8
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?


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.870 :
PostPosted: Wed Jul 12, 2017 10:36 pm 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6602
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.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.870 :
PostPosted: Thu Jul 20, 2017 12:38 am 
Offline

Joined: Wed Jul 12, 2017 10:51 am
Posts: 8
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?


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.870 :
PostPosted: Thu Jul 20, 2017 8:26 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6602
That is correct.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Template made by DEVPPL/ThatBigForum