107
jsp:setProperty and jsp:getProperty action tags
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.
Syntax of jsp:setProperty action tag
Example of jsp:setProperty action tag if you have to set all the values of incoming request in the bean
Example of jsp:setProperty action tag if you have to set value of the incoming specific property
Example of jsp:setProperty action tag if you have to set a specific value in the property
jsp:getProperty action tag
The jsp:getProperty action tag returns the value of the property.
Syntax of jsp:getProperty action tag
Simple example of jsp:getProperty action tag
Example of bean development in JSP
In this example there are 3 pages:
- index.html for input of values
- welocme.jsp file that sets the incoming values to the bean object and prints the one value
- User.java bean class that have setter and getter methods
index.html
process.jsp
User.java
Reusing Bean in Multiple Jsp Pages
Let’s see the simple example, that prints the data of bean object in two jsp pages.
index.jsp
Same as above.
User.java
Same as above.
process.jsp
second.jsp
Using variable value in setProperty tag
In some case, you may get some value from the database, that is to be set in the bean object, in such case, you need to use expression tag. For example:
process.jsp
Next TopicDisplaying Applet In Jsp