JSP STANDARD ACTIONS jsp:getProperty

                                                               jsp:getProperty
Introduction :

1.    The <jsp:getProperty>  action are used to retrieve data from  the bean as a String object.
2.     You must create or locate a Bean with <jsp:useBean> before you use <jsp:getProperty>.

Limitations:
You can use <jsp:getProperty> with JavaBeans components, but not with enterprise beans. As alternatives, you can write a JSP page that retrieves values from a Bean that in turn retrieves values from an enterprise bean, or you can write a custom tag that retrieves values from an enterprise bean directly.

Example:

getProperty
Getter   methods

<jsp: useBean id= “s” class= “Student”/>
<jsp: getProperty name= “s” property= “age”/>
<%
      Student s=new Student( );
      out. printIn (s.getAge( ));
   %>

Attributes:

<jsp: getProperty> tag contains the following 2 attributes

1.    Name :
The name of the bean object from which the required property is obtained.
It is exactly same   as id attribute of  jsp:useBean.

2.    Property : property name of  the  bean class to retrieve .

Test.jsp

<%@ page import = “pack1.*”>
<jsp:useBean  id= “s” calss= “pack1.Student”/>
Student Name: <jsp: getProperty  name= “s”  property= “name”/>
Student Mail   : <jsp: getProperty name= “s” property= “mail”/>

Student.java

package pack1;
Public class StudentBean
{
private String  name= “myjavahub”
private String  mail=”myjavahub2012@gmail.com”;
public String  getName ( )
{
          return name;
  }
public String getMail ( )
{
      return mail;
 }
}

Output:

Student Name:  myjavahub
Student Mail  : myjavahub2012@gmail.com

Thanks For Making This Possible! Kindly Bookmark and Share it.

Technorati Digg This Stumble Stumble Facebook Twitter

No comments:

Post a Comment