View Single Post
  #2 (permalink)  
Old 07-26-2007, 04:41 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: How can we use beans in JSP?

JSP provides three tags to work with beans:-

<jsp:useBean id=“bean name” class=“bean class” scope = “page | request | session|application ”/>
Bean name = the name that refers to the bean.
Bean class = name of the java class that defines the bean.
<jsp:setProperty name = “id” property = “someProperty” value = “someValue” />
id = the name of the bean as specified in the useBean tag.
property = name of the property to be passed to the bean.
value = value of that particular property .
<jsp:getProperty name = “id” property = “someProperty” />
Here the property is the name of the property whose value is to be obtained from thebean.Below is a code snippet which shows how MyUserClass is used and the valuesaccessed.

<jsp:useBean id="user" class="MyUserClass" scope="session"/>
<HTML>
<BODY>You entered
<BR>Name: <%= user.getUsername() %><BR>Email:
<%= user.getEmail() %><BR></BODY></HTML>
Reply With Quote