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

why 'class' and 'type' behave differently here?  RSS feed

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



Where Person is an abstract class.

It gives an error, because if there is no person object in request attribute then container try to creates new object for it and since it's an abstract class so....

My point is, if person object is in request attribute then it should not give any error...

Just like in case of type:



If attrubute exists in request (scope), container doesn't shout. Only if it is not exists then gives error.

Hope my question is clear.

Thanks.


[ December 15, 2005: Message edited by: rathi ji ]
 
Scott Selikoff
author
Bartender
Posts: 4081
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From your post, I think you can answer your own question. Its like passing an object by an Interface reference such as the List interface.

If it is given a List refernce and tries to instantiate it, it throws an error since this is not a concrete class. But, if it given an existing List (which might be an ArrayList or LinkedList for example), it just uses that object as it would any list.

Hope this is clear.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rathi,

Chapter JSP5 in the JSP Spec starts out with a well written description of useBean. There is a link to this spec in my signature.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I made my question very clear, I hope. Please read.

Ben, thanks but I am having HFS&J, the best book. May be after finishing HFS&J, I will read specification...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rathi ji:
Now I made my question very clear, I hope. Please read.

Ben, thanks but I am having HFS&J, the best book. May be after finishing HFS&J, I will read specification...


Rathi,
A book such as Head First Servlets/JSP, APIs, and the Specifications for the technologies are very distinct and different types of documentation. It makes no sense to get by with only one of them. They should be used in concert while learning and practicing Servlet/JSP development. It also makes no sense to approach them in a linear fashion.
Often reading one will clarify points made in the other.

The chapter I pointed out explains useBean very clearly and isn't a long read.

I don't think it's fair or reasonable to ask people to take the time to explain things to you if, in the same thread, you state that you aren't going to bother looking things up; even when someone hands you the link and gives you the exact location of the chapter that has the information that you want.
[ December 19, 2005: Message edited by: Ben Souther ]
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:


Rathi,
A book such as Head First Servlets/JSP, the librarie's API, and the specifications for the technologies are very distinct and different types of documentation. It makes no sense to get by with only one of them. They should be used in concert while learning and practicing Servlet/JSP development. It also makes no sense to approach them in a linear fashion.
Often reading one will clarify points made in the other.

The chapter I pointed out explains useBean very clearly and isn't a long read.

I don't think it's fair or reasonable to ask people to take the time to explain things to you if, in the same thread, you state that you aren't going to bother looking things up; even when someone hands you the link and gives you the exact location of the chapter that has the information that you want.


No Ben, I am rally sorry. I didn't meant that.
[ December 15, 2005: Message edited by: rathi ji ]
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
Did you read the chapter?
http://www.jcp.org/aboutJava/communityprocess/final/jsr152/


Sorry Ben, but I found it very tough to read.

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure it's possible to have a successful career as a programmer if you can't read specifications. The Servlet and JSP specs are some of the better written ones that I've seen.
I strongly recommend that you keep working on it.



6. If the object is not found in the specified scope, and the class specified names
a non-abstract class that defines a public no-args constructor, then the class is
instantiated. The new object reference is associated with the scripting variable
and with the specified name in the specified scope using the appropriate scope
dependent association mechanism (see PageContext). After this, step 8 is performed.
If the object is not found, and the class is either abstract, an interface, or no public
no-args constructor is defined therein, then a java.lang.InstantiationException
shall occur. This completes the processing of this jsp:useBean action.


Is this part clear to you?
You know that you can't instanciate an abstract class, right?
 
Stefan Evans
Bartender
Posts: 1834
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might find some easier reading here:
http://java.sun.com/products/jsp/syntax/1.2/syntaxref1217.html#8865

It defines the useBean tag and all the attributes you can use with it.

However you already seem to understand it. You described the difference in your original post.
"class" specifies the concrete class to create if necessary.
"type" specifies the type of bean it will create the scriptlet variable as.

ie
<jsp:useBean id="myList" type="java.util.List" class="java.util.ArrayList" scope="session"/>

translates roughly into java code like this:


They behave differently because they are defined to act like this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!