GeeCON Prague 2014*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jsp:useBean... confused Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jsp:useBean... confused" Watch "jsp:useBean... confused" New topic
Author

jsp:useBean... confused

Indunil Dasanayaka
Greenhorn

Joined: Dec 12, 2005
Posts: 11
can someone explain the behavior of this kind of jsp code

<jsp:useBean id="person" class="foo.Person" scope="request">
<jsp:setProperty name="person" property="firstName" value="Siripala"/>
</jsp:useBean>

<jsp:useBean id="person" class="foo.Person" scope="application">
<jsp:setProperty name="person" property="firstName" value="Siripala"/>
</jsp:useBean>

person's first name is = <jsp:getProperty name"person" property="firstName"/>

assume the class foo.Person is available to the above jsp.
what would be the result.

when i tried to execute this I got an exception.

y it gives an error. if i want to get the first name of the person who is in the application scope how could i get it.


Shit Happens...
Mike Pandey
Ranch Hand

Joined: Dec 05, 2005
Posts: 62
Hi Indunil

just think a bit more...apply ur java concepts once u understand what java code <jsp:useBean> translates into.

Can u have code like this

public void func() {
Integer obj=new Integer(56); //Wrapper object
Integer obj=new Integer(54);
}

think mate!!

All the best to u!!
Indunil Dasanayaka
Greenhorn

Joined: Dec 12, 2005
Posts: 11
but mike those are in two different scopes. first person is in the request scope and the otherone is in the application scope.
Mike Pandey
Ranch Hand

Joined: Dec 05, 2005
Posts: 62
Well Indunil

In your single translation unit, there will be two foo.Person objects with the same reference identifier "person" ...which obviously means a compiler error..ain't it?..

u r absolutely correct with the scopes...but just think on what i have written.
Indunil Dasanayaka
Greenhorn

Joined: Dec 12, 2005
Posts: 11
Yes i got it mike. Before it assign to the scope it has to declare two variables. How come they could have same name.

thanks lot mike.
 
GeeCON Prague 2014
 
subject: jsp:useBean... confused