About Question enthuware.jwpv6.2.870 :
Moderator: admin
-
- Posts: 55
- Joined: Thu Jan 03, 2013 7:51 am
- Contact:
About Question enthuware.jwpv6.2.870 :
if the getRequestDispatcher method returns null , shouldnt the call to forward throw NullPointerException.
or does the NPE gets wrapped by ServletException ??
or does the NPE gets wrapped by ServletException ??
-
- Site Admin
- Posts: 10326
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.jwpv6.2.870 :
Irrespective of whether a NPE is thrown or a ServletException is thrown, they will be caught by the catch(Exception) block.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 55
- Joined: Thu Jan 03, 2013 7:51 am
- Contact:
Re: About Question enthuware.jwpv6.2.870 :
oh thanks Paul.
-
- Posts: 1
- Joined: Mon Mar 30, 2015 1:32 am
- Contact:
Re: About Question enthuware.jwpv6.2.870 :
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
-
- Site Admin
- Posts: 10326
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.jwpv6.2.870 :
There is no need to know the location of login.jsp. No matter where it is kept, an exception will be thrown.
If you like our products and services, please help us by posting your review here.
-
- Posts: 9
- Joined: Wed Jul 12, 2017 10:51 am
- Contact:
Re: About Question enthuware.jwpv6.2.870 :
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?
-
- Site Admin
- Posts: 10326
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.jwpv6.2.870 :
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.
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 9
- Joined: Wed Jul 12, 2017 10:51 am
- Contact:
Re: About Question enthuware.jwpv6.2.870 :
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?
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?
-
- Site Admin
- Posts: 10326
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.jwpv6.2.870 :
That is correct.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 1 guest