• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bean Undefined Exception in JSP

 
Sandeep Deshmukh
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rajendar Goud
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

-raj
 
Sandeep Deshmukh
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Sandeep
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Rajendar said, you can do this from a scriptlet.


Ex:
<useBean id="myBean" class="pkg.myBean" scope="session" />
<% myBean.setMap(new HashMap()); %>
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic