<div dir="ltr" style="text-align: left;">
<div dir="ltr" style="text-align: left;">In this Tutorial we want to describe you a code that help in describing an example from JSP bean set property.<i><b>SetProperty </b></i>tag in JSP is used to set properties of the JAVA bean.</p>
<p>General syntex of JSP <b><i>setProperty </i></b>Tag look like this:<br />
<b>Syntax:</b></p>
<pre class="highlight"><;jsp:setProperty name="xyz" property="xyz" value="xyz"/>;</pre>
<p>The code include a package bean , we have a class Employees. The employee class include a string variable first name, last name and address. Inside the class we have a setter and getter method.<br />
1. set XXX ( ): This method hold the value of the parameter by the implementor of interface.<br />
2. get XXX( ): This method retrieve the value of the parameter set in the setXXX () method.<br />
The JSP page uses this getter and setter method.</p>
<p><b><;jsp:useBean>; &#8211; </b><br />
1. The <b><; jsp:use Bean>;</b> instantiate a bean class and locate a bean class with specific scope and name.</p>
<ul style="text-align: left;">
<li><b>id </b>&#8211; A id variable is used to identify the bean in the scope .</li>
<li><b>class </b>-The class is represented as Package. class and instantiate a bean from class. The class should be public</li>
<li><b>scope </b>-This describe you the scope of the bean in which it exists.</li>
</ul>
<p>2.<b> <;jsp:set Property>;</b> This is used to set the value of one or more properties of bean using setter method. The value of the name must match with the Id.<br />
3. <b><;jsp:get Property>;</b> This is used to return the bean property value using property getter method in bean package.</p>
<p><b>Example-</b><br />
<i><b>Employee.java</b></i></p>
<pre class="highlight">package com.dineshonjava.bean; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
public class Employee { 
 private String firstName; 
 private String lastName; 
 private String address; 
 
 public String getFirstName() { 
 return firstName; 
 } 
 public void setFirstName(String firstName) { 
 this.firstName = firstName; 
 } 
 public String getLastName() { 
 return lastName; 
 } 
 public void setLastName(String lastName) { 
 this.lastName = lastName; 
 } 
 public String getAddress() { 
 return address; 
 } 
 public void setAddress(String address) { 
 this.address = address; 
 } 
 
} 
</pre>
<p><i><b>index.jsp</b></i></p>
<pre class="highlight"><;%@page contentType="text/html"%>; 
<;%@page pageEncoding="UTF-8"%>; 
<;html>; 
 <;body>; 
 <;h1>;Employee Form Bean Value<;/h1>; 
 <;jsp:useBean id="emp" class="com.dineshonjava.bean.Employee" scope="page" />; 
 
 <;jsp:setProperty name="emp" property="firstName" value="Dinesh"/>; 
 <;jsp:setProperty name="emp" property="lastName" value="Rajput"/>; 
 <;jsp:setProperty name="emp" property="address" value="Noida"/>; 
 
 <;table>; 
 <;tr>; 
 <;td>;First Name<;/td>; 
 <;td>; : <;/td>; 
 <;td>; <;jsp:getProperty name="emp" property="firstName"/>; <;/td>; 
 <;/tr>; 
 <;tr>; 
 <;td>;Last Name<;/td>; 
 <;td>; : <;/td>; 
 <;td>; <;jsp:getProperty name="emp" property="lastName"/>; <;/td>; 
 <;/tr>; 
 <;tr>; 
 <;td>;Address<;/td>; 
 <;td>; : <;/td>; 
 <;td>; <;jsp:getProperty name="emp" property="address"/>; <;/td>; 
 <;/tr>; 
 <;/table>; 
 
 <;/body>; 
<;/html>; 
</pre>
<p>Copy <b>myapp </b>folder on <b>webapp </b>directory of tomcat at<br />
<i><b>C:Program Files (x86)Apache Software FoundationTomcat 7.0webapps</b></i></p>
<p>and restart server and hit the following URL<br />
<i><b>http://localhost:8080/myapp/index.jsp</b></i></p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/09/1111-3.png" border="0" /></div>
<p><b><a href="https://sites.google.com/a/dineshonjava.com/dineshonjava/dineshonjava/myapp.zip?attredirects=0&;d=1" target="_blank" rel="noopener">Download Example</a></b></p>
</div>
<p> ;</p>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/jsp-usebean-tag/">Previous</a> <;<; || <a href="https://dineshonjava.com/jsp-tutorial-baby-step-to-server-pages/">Index </a>|| >;>;<a href="https://dineshonjava.com/getproperty-tag-in-jsp/">Next</a> >;>;</b></div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/jsp-usebean-tag/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/getproperty-tag-in-jsp/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '337'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…