Thursday, April 14, 2011

Chapter 43: Accessing JavaBeans in JSP

We have learnt almost everything we need to, about java beans and using them in JSP pages. The last chapter in the series on JavaBeans is about accessing JavaBean components in JSPs using all possible ways.

So lets get started!!!

Accessing a Declared JavaBean Component

We know how to declare a JavaBean and use it. But, there is one extra thing, there are many ways of using these beans. We can access them using scriptlets or expressions or xml elements. Let us see examples about each of these ways.

Example: Accessing a Bean Property

Using XML:

< jsp : getProperty name = “addressBean” property = “city” … / >

Using Scriptlets:

< % String city = objAddress.getCity() % >

Using Expression:

< % = objAddress.getCity() % >

Exam Trivia
Question: What are the three ways to reference a bean in JSP?
Answer: A JavaBean can be referenced in three ways: through an expression, scriptlet, or XML tag.

Previous Chapter: Chapter 42 - JavaBeans Scope

Next Chapter: Quick Recap - Chapters 38 to 43

No comments:

Post a Comment

© 2013 by www.inheritingjava.blogspot.com. All rights reserved. No part of this blog or its contents may be reproduced or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission of the Author.

ShareThis

Google+ Followers

Followers