JSP - SPLessons

JSP setProperty-getProperty

Home > Lesson > Chapter 28
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

JSP setProperty-getProperty

JSP setProperty and getProperty

shape Description

JSP setProperty-getProperty - The jsp: setProperty activity tag is utilized to set property estimations in a bean utilizing setter method. The setProperty uses java bean for the development of web application. Syntax
<jsp:setProperty name="instanceOfBean" property= "*"   |  property="propertyName" param="parameterName"  |   property="propertyName" value="{ string | <%= expression %>}" /> 
The jsp: getProperty action tag is utilized to get property estimations in a bean utilizing getter strategy. This getProperty is used for web application with java bean. Syntax
<jsp:getProperty name="instanceOfBean" property="propertyName" />  

JSP setProperty-getProperty 

shape Example

Following is the best example to understand the JSP setProperty-getProperty.  Details.java [java] package com; public class Details { private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } } [/java] JSP setProperty-getProperty - Here created two text fields username and password, written methods getUsername() and getPassword() to retrieve the user name and password. For the data members the developer used private keyword means that encapsulation concept. user.jsp [java] //useBean, getProperty and setProperty example <form action="userdetails.jsp" method="post"> User Name: <input name="username" type="text" /> User Password: <input name="password" type="password" /> <input type="submit" value="register" /> </form> [/java] Here included userdetails.jsp file in form method. userdetails.jsp [java]<jsp:usebean class="com.Details" id="userinfo"></jsp:usebean> <jsp:setproperty name="userinfo" property="*"</jsp:setproperty> You have entered below details: You have entered below details: UserName: <jsp:getproperty name="userinfo" property="username"></jsp:getproperty> Password: <jsp:getproperty name="userinfo" property="password"></jsp:getproperty>[/java] Output Output will be as follows with two text fields one for username and another for password and register button also. After entering the username and password output will be as follows.

Summary

shape Key Points

  • JSP setProperty-getProperty used to build dynamic application with java bean.
  • jsp:setProperty activity label sets a property estimation or qualities in a bean utilizing the setter strategy.