|
How to get and set the property of a JavaBean class |
|
|
This example shows the way of getting and setting the property of a JavaBean class. This example uses <jsp:useBean>, <jsp:getProperty> and <jsp:setProperty> tags of the JSP.
The following JSP page sets and gets the message property to value “Hello Rohit” of Simple Bean.
<html>
<head>
<titile>Demo resuing java beans in jsp</title>
</head>
<center>
<table border = 5>
<tr><th>
Re using javaBeans in JSP </table>
</center>
<p>
<jsp:useBean id ="test" class="beans.SimpleBean"/>
<jsp:setProperty name="test" property="message" value="Hello Rohit"/>
<h1>Message: <i>
<jsp:getProperty name = "test" property="message"/>
</i></h1>
</body>
</html>
SimpleBean.java
public class SimpleBean {
private String message = "No message specified";
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
|
Output:
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.