CHAPTER 2: Building Web Applications Using Servlets and JSP 85
The useBean action is used to declare and initialize the bean object. Once the bean is initialized,
you can use the jsp:setProperty and jsp:getProperty actions to set and get bean properties
The
The
The
<jsp:setProperty name="someId" property="someProperty" .../>
The
property is not a string, it converts it to a string.
The
<jsp:getProperty name="someId" property="someProperty" .../>
Listing 2-25 shows how to create a user bean, and Listing 2-26 shows the usage of these three
actions in a JSP page.
Listing 2-25. User Bean
1.package com.apress.jspactions;
2.
3.public class User {
4.
5.private String name;
6.
7.public String getName() {
8.return name;
9.}
10.
11.public void setName(String name) {
12.this.name = name;
13.}
14.
15.}
The user bean in Listing 2-25 will be used in user.jsp, which is shown in Listing 2-26.
Listing 2-26. user.jsp
1.
2.
3.
4.
5.
6.
7.Hello
8.
9.