aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes ServletContext getRequestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "ServletContext getRequestDispatcher" Watch "ServletContext getRequestDispatcher" New topic
Author

ServletContext getRequestDispatcher

padma jyotsna
Greenhorn

Joined: Jun 07, 2010
Posts: 17
Hi

according to the API, when getRequestDispatcher() is called on ServletContext object, absolute path must be given.. right?

I would like to know what happens if ServletContext.getRequestDispatcher() is given a relative path as the argument.
Will it give rise to IllegalStateException or NullPointerException?

are the SCWCD questions specific about the name of the exception?


Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

1) Why don't you try to create a program to see what happens when you pass a relative path to the ServletContext.getRequestDispather method.
2) The exam is designed in such a way that you don't have to memorize all the stuff. Anything asked in the exam will be logical. So if what exception a method throws is logical, then it can be on the exam...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
padma jyotsna
Greenhorn

Joined: Jun 07, 2010
Posts: 17
I have written some code and checked out
It gave an IllegalArgumentException.

I happen to read in some mock question that NullPointerException arises. I believe that is wrong answer.

please correct me if I am wrong.


Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

The answer must be wrong in the mock exam I guess...
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1676
    
  25

Hi Padma & Ankit,

It actually depends on the question being asked. it will throw an IllegalArgumentException if the path doesn't start with a "/" but it will throw a NullPointerException if path (the String object) is still null.

Regards,
Frits
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: ServletContext getRequestDispatcher