This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
I have been playing with this code , but I am not sure about some of the results I got.
If some one could help me with that .. that would be great!
Person File :
Employee File :
And finally PrintBean.jsp
I change the <jsp:useBean id="person" class="foo.Employee" type="foo.Person" scope="page"> to get different results.
1) class="foo.Person"The value for the useBean class attribute foo.Person is invalid - I dont get this. Even if I dont mention EmpId which is not accessible to the person instance even then i get the same error.And the Person class is not even Abstract
2)type= "foo.Person" Cannot find any information on property 'empId' in a bean of type 'foo.Person' -This makes sense as it cannt access EmployeeId
3)type="foo.Employee"bean person not in scope - What exactly do you mean by "bean is not in scope"
4)class="foo.employee" works fine -Makes sense.Creates an instance of type employee
5)class="foo.Person" type="foo.Person"The value for the useBean class attribute foo.Person is invalid -Not sure about this one.
6)class="foo.Employee" type="foo.Employee"works fine Reference n object of type Employee .ok!
7)class="foo.Employee" type="foo.Person"works fine Reference of Person.Object of Employee.Ok!
8)class="foo.Person" type="foo.Employee"The value for the useBean class attribute foo.Person is invalid Cannot have refernce of the child class.ok!
Can some one explain thee reason for the other errors i didnot get.
Also,i am not sure the significance of the scope and its use. How can I test code to understand the difference between the difference scopes.
The future belongs to those who believe in the beauty of their dreams.Dream BIG!
3)type="foo.Employee" bean person not in scope
- What exactly do you mean by "bean is not in scope"
if you use type without class attribute, this Employee bean must already present in specified scope. so, in servlet from which you are dispatching request, instance of employee bean must be added in page scope.
foo.Employee emp = new foo.Employee();
//setters of elements of emp
This will make sure that person bean is in scope(page), and getAttribute uses this person bean.
SCJP 1.4, SCWCD 1.5
Joined: Nov 05, 2007
Is there any way using scriptless JSP to find out if a bean exists or not..?