Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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: 9597
36
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: 9597
36
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
Posts: 2781
174
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
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!