Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

When to use CLASS or TYPE  RSS feed

 
R K Parulekar
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I'm new to jsp and not very sure when to use CLASS or TYPE arguments in following jsp statement ..
<jsp:useBean id="myclass" CLASS="test.MyClass" TYPE="test.MyClass" scope="request" />

Sometimes it gives error "Bean not within the scope"
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use "class" the JSP page will attempt to instanciate the object if one is not found in the given scope.
Type is for giving a local name to an object instanciated elswhere.


The JSP spec is a good place to find anwswers to questions like this:

JSP.5.1 <jsp:useBean>
A jsp:useBean action associates an instance of a Java programming language object defined within a given scope and available with a given id with a newly declared scripting variable of the same id. When a <jsp:useBean> action is used in an scriptless page, or in an scriptless context (as in the body of an action so indicated), there are no Java scripting variables created but instead an EL variable is created. The jsp:useBean action is quite flexible; its exact semantics depends on the attributes given. The basic semantic tries to find an existing object using id and scope. If the object is not found it will attempt to create the object using the other attributes. It is also possible to use this action to give a local name to an object defined elsewhere, as in another JSP page or in a servlet. This can be done by using the type attribute and not providing class or beanName attributes. At least one of type and class must be present, and it is not valid to provide both class and beanName. If type and class are present, class must be assignable to type (in the Java platform sense). For it not to be assignable is a translationtime error. The attribute beanName specifies the name of a Bean, as specified in the JavaBeans specification. It is used as an argument to the instantiate method in the java.beans.Beans class. It must be of the form a.b.c, which may be either a class,




 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!