The following example code demonstrates useBean Directive in JSP.

public class Person {
   private String name;
   private int age;
   private String address;
   public Person(String name, int age, String address) { = name;
      this.age = age;
      this.address = address;
   public String getName() {
      return name;
   public int getAge() {
      return age;
   public String getAddress() {
      return address;


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html>
<meta charset="ISO-8859-1">
<title>Person Page</title>
   <jsp:useBean id="person" class="Person" scope="page">
      <jsp:setProperty name="person" property="name" value="John Doe"/>
      <jsp:setProperty name="person" property="age" value="30"/>
      <jsp:setProperty name="person" property="address" value="123 Main St"/>
   <h2>Person Details</h2>
   <p>Name: <%= person.getName() %></p>
   <p>Age: <%= person.getAge() %></p>
   <p>Address: <%= person.getAddress() %></p>

In this example, Person is a Java class that has three properties: name, age, and address. The PersonPage.jsp uses the useBean directive to create an instance of the Person class and sets its properties using the setProperty directive.

The properties of the Person object are then displayed on the page using expressions. When the PersonPage.jsp is executed, it will display the person’s name, age, and address on the page.

Further Reading

Spring Framework Practice Problems and Their Solutions

Java Practice Exercise