• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

WhizLabs Question : jsp:useBean

 
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

Could you please help me out ?

Question :

What will be the result of accessing a JSP page containing this code using the URI /test/a.jsp?intValue=3



a) Prints 3
b) Prints 0
c) Does not compile
d) Throws an exception

I thought this code would not compile because Integer class does not have a default no-args constructor as required by <jsp:useBean> element.

But according to WhizLabs, this code would throw a InstantiationException.

Am I wrong ?
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess its would throw an instantiation Exception as the the class the Wrapper Interger class cannot be instantiated. This will take place at runtime so it will throw instantiation error...! So your Answer compilation Error is wrong..!
[ October 28, 2006: Message edited by: Nilesh Raje ]
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I might be wrong but to my understanding when the jsp is translated it will generate a code like



and since a no-arg constructor doesn't exist, the code won't compile. How can that cause a RunTimeException?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is an excerpt from JSP specification

If the class attribute is used for a Java type that cannot be instantiated as a JavaBean, the container may consider the page invalid, and is recommended to (but not required to) produce a fatal translation error at translation time, or a java.lang.InstantiationException at request time.


So the answer can both be translation time error or InstantiationException when request is received...
 
Alex Serna
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ankit,

Still, to me translation error makes sense, but an Exception at request time... let's say our jsp was loaded on startup... first it would be translated and after that compiled(no request would have come yet, I think this isn't considered request time yet). IMO this wouldn't make it to the first request, it would fail at compilation time.

What do you think?


 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the excerpt from the spec again, it doesn't say an exception at the first request. What I think it means is that there will be an exception at every request to that page, not when the page is translated or at compile time. So you can catch that exception using c:catch or try-catch or use an exception page in response to the InstantiationException...
 
Alex Serna
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I'll just think about it as something it will happen at request time...

Thank you Ankit!
 
We don't have time to be charming! Quick, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic