This article is more than ten years old and potentially contains out-dated information.
작성한지 10년 이상 지난 게시물입니다. 최신의 정보와 맞지 않는 내용을 포함할 수도 있습니다.

What are JavaBeans?

JavaBeans are software components written in the Java programming language. Well, this kind of explanation probably would not be helpful.

How to use JavaBeans?

Here’s a simple example.

beans/Bean.java
/**
 *
 * @author superwtk
 */
public class Bean {

	private String name;

	/** Creates a new instance of Bean */
	public Bean() {
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
bean.jsp
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>JSP Page</title>
  </head>
  <body>
	<jsp:useBean id="bean" class="beans.Bean">
	  <jsp:setProperty name="bean" property="name" value="An example of Bean" />
	</jsp:useBean>


	  With JSTL:
	  <c:out value="Name: ${bean.name}" />
	


	  With scriptlet:
	  <%
		out.println("Name: " + bean.getName());
	  %>
	

  </body>
</html>

The following bunch of code

<jsp:useBean id="bean" class="beans.Bean">
  <jsp:setProperty name="bean" property="name"
   value="An example of Bean" />
</jsp:useBean>

has the same effect with

beans.Bean bean = new beans.Bean();
bean.setName("An example of Bean");

For getting more information, refer to:

References

</ul>