• 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • 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: 356
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

 
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic