This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

<jsp:useBean> compilation error vs runtime error

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 357
2
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • 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

 
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic