Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Compile error or runtime exception?  RSS feed

 
Jeff Wachhorst
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Help! I'm having a problem with Tomcat and cannot test this yet-
If you have a JSP containing the following:

<jsp:useBean id="myBean" class="java.lang.Integer" />
<%=myBean%>

Assuming that myBean does not yet exist, would this code fail to compile or throw an exception at request time? Whoever wrote this question is saying runtime exception but I'm not so sure. Why wouldn't it be a compile error? When an attempt is made to instantiate myBean, class Integer hasn't got a no-arg constructor. That'd be a compile error yes?

By the same token,

<jsp:useBean id="myBean" class="java.lang.Integer" />
<jsp:setProperty name="myBean" property="*" />
<%=myBean%>

The author of this one also says runtime exception.

Finally,

<jsp:useBean id="beanOne" class="MyBean" scope="application" />
<jsp:setProperty name="beanOne" property="name" param="name1" />
<%=beanOne.getName()%>

The author of this question says compile error!

Thank you SO much in advance for any help!!
[ July 07, 2004: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Assuming that myBean does not yet exist, would this code fail to compile or throw an exception at request time?


The answer is: it depends.

Under Tomcat 5, your first example does indeed fail with a translation time error ('cannot resolve symbol' to be exact). Resin 2, on the other hand was smart enough to realize that Integer has no no-arg constructor, and encodes the JSP to throw an InstantiationException if the bean does not already exist.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!