File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Jsp:useBean Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Jsp:useBean Problem" Watch "Jsp:useBean Problem" New topic

Jsp:useBean Problem

Geeta Gune

Joined: Mar 19, 2002
Posts: 17
How to instantiate the class using jsp:usebean when the class contains a constructor with arguments and does not contain a no-args constructor?? is it possible??
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
I don't believe it is possible because the javabean specification states that javabeans must have a no-arg constructor.

Matthew Phillips
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63870

It is not possible. If you look at any Java class generated from a JSP that uses the <jsp:useBean> tag, you will see that an instance of the bean is automatically created using the no-args contructor if no bean of that name already exists in the scope specified by the tag.
So if the "bean" class does not have a no-args contructor, the JSP class will not compile.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Jsp:useBean Problem
jQuery in Action, 3rd edition