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> |