• 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

<jsp:useBean> compilation error vs runtime error

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Issue: compilation error vs runtime error

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

When we use the class as java.lang.Integer it would throws an Instantiation Exception

However, if we use <jsp:useBean id="intBean" class="com.myclass" /> such that

public class myclass{

myclass(int a){} //parametrized constructor
private int intBean;
//getter + setter of intBean

}
Then the <jsp:useBean would cause a compilation error.

Could anyone suggest the possible reason behind this?
 
Ranch Hand
Posts: 384
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sarvath,

Your myclass needs a no-argument constructor.
<jsp:useBean> initializes the bean with the no-argument constructor of the specified class.

Hope this helps.
 
Sarvarth Bhatnagar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lalit Mehra wrote:Hi Sarvath,

Your myclass needs a no-argument constructor.
<jsp:useBean> initializes the bean with the no-argument constructor of the specified class.

Hope this helps.




Hi Lalit,
my question is why do we get compilation error when we use an argument constructor:: com.myclass(in this case).
and On the contrary, we get an Exception when we go for a predefined API WrappeClass, why dont we get compilation error here too?
java.lang.Integer also has an argument constructor


 
Ranch Hand
Posts: 376
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Assuming you have created the custom class correctly, it should compile in both cases.

Are you creating package called "com" ?

i.e.:





Otherwise, please post the compilation error you are facing.

--German

 
reply
    Bookmark Topic Watch Topic
  • New Topic