• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using type without class - page 354

 
H Singh
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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
 
kapil munjal
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic