• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

use of bean in jsp

 
abhishek paliwal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
i am facing a problum in using java bean in jsp.
i am sending the sample code here.
bean is:
package op;
import java.io.*;
class exam
{
String name;
exam(){};
public void setname(String r)
{
name=r;
}
public String getname()
{
return name;
}
}
this file is stored in my application's WEB-INF's classes's op folder.
i am using bean in jsp as
<jsp:useBean id="db" class="op.exam" scope="request"/>
.
.
but this gives the error "The value for the useBean class attribute 'op.exam' is invalid."
please help me.
thankx
 
Kalyana Sundaram
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Simple clue would be just restart the Server and check again !!!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple things:

1.) When posting more than a line or two of your code, wrap the code in a set of UBB Code tags. This will preserve your indenting and make your code much easier to read (usually resulting in more people reading it and, thus, more help).

2.) Use the standard Java naming/capitalization conventions.
Class names should start with a capital letter. Object variables for those classes should be spelled the same but start with a lower case letter. This makes it very easy for people reading your code to understand the difference between the two.

When you say "this file" is stored under WEB-INF/classes/op, what file do you mean? A source file (.java) or did you compile the bean class and put the .class file there?
 
Stefan Evans
Bartender
Posts: 1784
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To qualify as a bean, your class must have a public constructor that takes no arguments.

Suggestions

make your class public
make the constructor for it public
And as Ben said, follow standard java coding conventions to make it easier for others to understand your code.

Cheers,
evnafets
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic