Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using type without class - page 354

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens when we declare a type, but not a class ?

JSP
<jsp:useBean id="person" type="foo.person" scope="page" >

Result if the person attribute already exists in "page" scope:

It works perfectly

Result if the person attribute does not exist in the "page" scope:

javax.servlet.ServletException: bean person not found within scope


I am not able to understand - what will make the person attribue available in the page scope (for the above JSP) ?

Thanks
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

JSP
<jsp:useBean id="person" type="foo.person" scope="page" >

1. Result if the person attribute already exists in "page" scope:

It works perfectly

2. Result if the person attribute does not exist in the "page" scope:

javax.servlet.ServletException: bean person not found within scope


1. This work perfectly because it will be able find a request attribute and it will try to work on that bean.

2. If it will not find any beans with the name person then it will throw ServletException.

All this is about having the bean already in scope.

If we exchange 'type' with 'class', then it will look for the bean and it doesn't find it in scope then it will make it available in the scope.
 
brevity is the soul of wit - shakepeare. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic