Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContext getRequestDispatcher

 
padma jyotsna
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
padma jyotsna
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer must be wrong in the mock exam I guess...
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2275
80
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic