Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean

 
S Kusa
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I came across some questions and they are as follows:
I feel that answers to them are not correct, could someone respond to this message and cofirm.

1. id used in jsp:useBean should "always match" with the name in jsp:getProperty, is it correct?

As per the answer given to this question, it could be different like id=emp and name in getProperty as name=empObj

2. To download the contents of the jar file two prerequisites are
-- the setContentType "must be" set to "application/jar"
-- and outputstream should be acquired as response.getOutputStream()

As per answer to this question,
outputstream should be acquired as response.getOutputStream()- this is correct
but response.setHeader("Content-Type","text/html") should be used.


3. one more problem statement- When the same class is available in the WEB-INF/classes and a jar file under WEB-INF/lib, class available in the jar file stored under WEB-INF/classes is loaded
I feel it should be class under WEB-INF/classes and not jar file under WEB-INF/classes.

Could someone pl. answer these questions.
 
Ernesto Leyva
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check Table JSP.5-2 in JSP Specification it says the "name" in <jsp:setPorperty> can be defined with <jsp:useBean> meaning the "id" property.

Yes I think a jar file is always in WEB-INF/lib never in WEB-INF/classes
 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 'id' attribute in jsp:useBean and 'name' attribute in jsp:getProperty need not be same.
The id attribute is the beanInstance.
The 'name' attribute can be the same bean instance or reference to the 'id' attribute.


<jsp:useBean id="person" class="servlettest.Person" scope="request"/>
<jsp:getProperty name="person1" property="name"/>


look at this code ,here 'id' and 'name' is different.
But i can retrieve the name property....it will not cause any exception/error.


Thanks.
 
Veena Pointi
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vinod NS:
The 'id' attribute in jsp:useBean and 'name' attribute in jsp:getProperty need not be same.
The id attribute is the beanInstance.
The 'name' attribute can be the same bean instance or reference to the 'id' attribute.


<jsp:useBean id="person" class="servlettest.Person" scope="request"/>
<jsp:getProperty name="person1" property="name"/>


look at this code ,here 'id' and 'name' is different.
But i can retrieve the name property....it will not cause any exception/error.


Provided person1 attribute exists! It throws exception if it doesn't exist.

My Conclusion :
This means ,name you use in jsp:getProperty is not dependent on id in jspuseBean as long if bean exists...
[ March 21, 2006: Message edited by: Veena Point ]
 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what i wanted to emphasize is that 'id' and 'name' need not be the same bean instance.The 'name' attribute can be the reference to the 'id' attribute,here person1 is a reference of person.

look at my servlet code,

Person p = new Person();
p.setName("javaranch");
request.setAttribute("person",p);
Person p1=new Person();
p1 = p;
request.setAttribute("person1",p1);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic