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

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Bean Undefined Exception in JSP" Watch "Bean Undefined Exception in JSP" New topic

Bean Undefined Exception in JSP

Sandeep Deshmukh

Joined: Dec 06, 2004
Posts: 16
Hi Guys,

Let me tell the scenario.
I fill 6 items in a html form with action attribute going to a JSP page 'insertitems.jsp' which retrieves these items using request.getParameter(). These items are put in a HashMap.
I wrote a bean class 'mybean' with a set method setFields(HashMap) and a int getInsertedFlag(). In the class a Hashmap is its member variable.
The set method sets the hashmap sent by JSP to the beans hashmap.
The get method inserts the 6 items in database using JDBC and returns updation status.

'mybean' class has compiled and placed in a package.

The 'insertitems.jsp' uses usebean tag wth id="mybeanid" and then setproperty tag to set the hashmap.
Later using the beans id I call the get method in a scriplet like mybeanid.getinsertedFlag() instead of get property tag.
Here the Compiler gives error that the id is undefined.
'insertitems.jsp' hasnt got compiled as a result.
Cant I use beans id that way.

Please Comment.

Sandeep Deshmukh

Java and Oracle Programmer
Rajendar Goud
Ranch Hand

Joined: Mar 06, 2002
Posts: 220
Hi sandeep,
you can invoke the method in scriptlet instead of using the get property tag.why dont u post the code and the exception you are facing

Sandeep Deshmukh

Joined: Dec 06, 2004
Posts: 16
Hi Guys

Thanks to Rajendra for replying to my query.
Actually there was a typing error.
Still I had to compromise on 1 matter regarding useBean tag in JSP.
The param attribute in setProperty can only be from request parameters.
If I want to use my own variable in JSP page such as a HashMap to be passed param does not pass it to the bean.
value attribute can have constants as their value. How can I pass my own refernce objects in setProperty tag using either param or value attribute.

Please Comment.

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

As Rajendar said, you can do this from a scriptlet.

<useBean id="myBean" class="pkg.myBean" scope="session" />
<% myBean.setMap(new HashMap()); %>

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Bean Undefined Exception in JSP
It's not a secret anymore!