wood burning stoves 2.0*
The moose likes JSP and the fly likes <jsp:useBean> compilation error vs runtime error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "<jsp:useBean> compilation error vs runtime error" Watch "<jsp:useBean> compilation error vs runtime error" New topic
Author

<jsp:useBean> compilation error vs runtime error

Sarvarth Bhatnagar
Greenhorn

Joined: Jan 16, 2013
Posts: 9
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?
Lalit Mehra
Ranch Hand

Joined: Jun 08, 2010
Posts: 384

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.


http://plainoldjavaobject.blogspot.in
Sarvarth Bhatnagar
Greenhorn

Joined: Jan 16, 2013
Posts: 9
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


German Gonzalez-Morris
Ranch Hand

Joined: Nov 16, 2009
Posts: 153

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


http://devwebcl.blogspot.com/
 
jQuery in Action, 2nd edition
 
subject: <jsp:useBean> compilation error vs runtime error
 
Similar Threads
Compilation fails vs runtime exception
hide vs override
jsp:beans - class must be instantiated - but why?
== Vs equals()
jsp:useBean query