jsp:useBean as in MVC compared to standaalone JSP

Hi,

I was reading as below


jsp:useBean as in  MVC

AS JSP page should not create the objects

servlet(not JSP page), should create all the data objects. To ensure JSP page will not create
objects, we should say like below.
<jsp:useBean ... type="package.Class" scope="request" />

instead of

<jsp:useBean ... class="package.Class" scope="request"/>

Note:
scope is not used in MVC (Model 2) architecture


<jsp:useBean id="..." type="..." />




JSP should never modify the objects
 
 So say jsp:getProperty
but not

jsp:setProperty.
 


 




I have not clearly understood what it means. How 'type' and 'class' are different. When to use use which one and advatages, disadvantages of using each one of them.

Please advise.

Any links resources ideas highly appreciated. Thanks in advance
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

girionisCommented:
The type there is the class of the object. It simply means that the specific bean is of type xxx.yyy.Z.
0
gudii9Author Commented:

line1
<jsp:useBean ... type="package.Class" scope="request" />

line2
<jsp:useBean ... class="package.Class" scope="request"/>



when to use line1

when to use line2

please advise
0
girionisCommented:
The semantics are different for the two lines. The first line will try to find an existing bean and assign it a type defined in the "type" attribute. The second line will try to create a bean from the class specified in the "class" attribute.

You can also use these tags together.

Have a look at the JSP tags reference:

class="package.class"

Instantiates a bean from a class, using the new keyword and the class constructor. The class must not be abstract and must have a public, no-argument constructor. The package and class name are case sensitive.

type="package.class"

If the bean already exists in the scope, gives the bean a data type other than the class from which it was instantiated. The value of type must be a superclass of class or an interface implemented by class. If you use type without class or beanName, no bean is instantiated. The package and class name are case sensitive.

class="package.class" type="package.class"

Instantiates a bean from the class named in class and assigns the bean the data type you specify in type. The value of type can be the same as class, a superclass of class, or an interface implemented by class. The class you specify in class must not be abstract and must have a public, no-argument constructor. The package and class names you use with both class and type are case sensitive.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.