This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "ServletContext getRequestDispatcher" Watch "ServletContext getRequestDispatcher" New topic

ServletContext getRequestDispatcher

padma jyotsna

Joined: Jun 07, 2010
Posts: 17

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

Joined: Aug 03, 2008
Posts: 9291

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

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

Joined: Aug 03, 2008
Posts: 9291

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

Joined: Apr 07, 2010
Posts: 1646

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.

I agree. Here's the link:
subject: ServletContext getRequestDispatcher
Similar Threads
*** RequestDispatcher doubt ***
problem with RequestDispatcher
getRequestDispatcher() clarification
Correct answer