useBean

package com.ourownjava.jsp.bean;
/**
* @author ourownjava.com
*/
public class User {

private String firstName;
private String lastName;

public String getFirstName() {
return firstName;
}
public void setFirstName(final String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(final String lastName) {
this.lastName = lastName;
}
}
 
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jsp.ourownjava.com</title>
</head>
<body>
    <jsp:useBean id="userBean" scope="request">
        <jsp:setProperty name="userBean" property="firstName" value="jsp"/>
        <jsp:setProperty name="userBean" property="lastName" value="ourownjava.com"/>
    </jsp:useBean>         
    First Name: <jsp:getProperty name="userBean" property="firstName" /> <br/>
    Last Name: <jsp:getProperty name="userBean" property="lastName" />
</body>
</html>

Leave a comment

Your email address will not be published. Required fields are marked *