This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Problem in declaring a bean in JSP page 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 "Problem in declaring a bean in JSP page" Watch "Problem in declaring a bean in JSP page" New topic
Author

Problem in declaring a bean in JSP page

Priyanka Gupta
Greenhorn

Joined: Apr 16, 2005
Posts: 4
I am using the below statement in my JSP page -
<jsp:useBean id="dashboard" scope="application" class="com.solvcentral.solvdashboard.admin.AdminDashboard" />

where my JAVA BEAN is - AdminDashboard

when I run the JSP page on my Explorer, it gives me the below error -
StackTrace
java.lang.InstantiationException: class com.solvcentral.solvdashboard.admin.AdminDashboard : java.lang.InstantiationException: com.solvcentral.solvdashboard.admin.AdminDashboard
at org.apache.jsp.usermanager_jsp._jspService(usermanager_jsp.java:85)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1040)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1151)
at java.lang.Thread.run(Thread.java:534)
[ April 16, 2005: Message edited by: Bear Bibeault ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Does AdminDashboard have a zero argument constructor?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Priyanka Gupta
Greenhorn

Joined: Apr 16, 2005
Posts: 4
Constructor for AdminDashboard is not a zero argument constructor.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

UseBean is for Beans.
In order to be a bean, your class needs a zero argument constructor.
Fraund Bei
Greenhorn

Joined: Feb 28, 2005
Posts: 11
yes,that's right,in order to useBean,your class should comform with the java bean standart which means 0 arguments constructor and getter and setter for each properties.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60764
    
  65

"frank",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


Originally posted by Priyanka
-----------------------------
Constructor for AdminDashboard is not a zero argument constructor.


Even if you push in a no-args constructor to avoid the exception, your application will not work correctly if your bean is dependent on being initialized via the non-zero args constructor.

1. Provide a no-args constructor.
2. If the bean's initialized in a servlet, you could use the non-zero args constructor to initialize the bean before setting it in the specified scope.
3. If the bean is initialzed in a jsp , via the useBean tag, for all the variables that are currently initialized in the non-zero args constructor, make a call to the respective setter methods or use <jsp:setProperty .../>

ram.
Dhiraj Srivastava
Ranch Hand

Joined: Aug 29, 2001
Posts: 49
Hi Priyanka,

There is a diff between a bean class and a simple Java Class. In order to use bean you have three things.

1. A default constructor
2. Setter and getter methods
3. Implementing the Serializable or externizable interface.

But, fortunately we don't need all these... :-)

The problem might there is in the class attribute of your usebean std. action.

You simply create a method in your helper class named display()

public String display()
{
return "Hello World!!"
}

Then in the jsp page write:
<%=
[id](which you have set in the "id" attribute].display()
%>

Check this first..

I hope u got the point.. :-)
 
Consider Paul's rocket mass heater.
 
subject: Problem in declaring a bean in JSP page
 
Similar Threads
DynaActionForm - Exception creating bean
Error in JSP
isOutdated Compiler?
JSP-DataBase problem
Error while trying NewsLetter Example