<jsp:setproperty name="Test" property="*">
What does this mean?
I know the definition is, "Sets a property in the specified JavaBean instance". So what is it setting a property in the javaBean test too ?
The setProperty and getProperty action tags are used for developing web application with Java Bean. In web devlopment, bean class is mostly used because it is a reusable software component that represents data. The jsp:setProperty action tag sets a property value or values in a bean using the setter method.
The jsp:useBean, jsp:setProperty and jsp:getProperty tags are used for bean development. So we will see these tags in bean developement.
The getProperty action is used to retrieve the value of a given property and converts it to a string, and finally inserts it into the output.
Here is a complete example:
Form.html
<form method="POST" action="processForm.jsp">
<input name="name"/>
<input name="username"/>
<input name="jobTitle"/>
<input name="city"/>
<input type="submit">
The form collects input from the user and posts it to the processForm.jsp page.
processForm.jsp
<%@ page import = "com.Employee"%>
...
<jsp:useBean id="employee" type="com.Person" class="com.Employee">
<jsp:setProperty name="employee" property="*"/>
</jsp:useBean>
The <jsp:useBean>
action creates an object of type com.Person referred to by a com.Employee reference.
The <jsp:setProperty>
action matches the name of each of the input elements with the name of the getter method in the Employee object.
For example: name
matches with getName
and jobTitle
matches to getJobTitle
. Below is the Employee class. I have not included the Person interface.
Employee.java
public class Employee implements Person{
private String name;
private String username;
private String jobTitle;
private String city;
public String getJobTitle() {
return jobTitle;
}
public void setJobTitle(String jobTitle) {
this.jobTitle = jobTitle;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getUsername() {
return username ;
}
public void setUsername(String username) {
this.username = username;
}
}
Things to note about this standard action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With