In this Tutorial we want to describe you a code that help in understanding Java bean example in JSP.
In this Tutorial we want to describe you a code that help in understanding Java bean example in JSP.In this Tutorial we want to describe you a code that help in understanding Java bean example in JSP.This code illustrates the procedure of handling session and print a Hello world using Java Bean. The Bean is reusable code, portable and platform independent component written in a java programming language. The given below code helps you to understand the concept of Java bean.
Understand with Example
In this example we want to describe you a code that explain JavaBeans in JSP.For this we have to create a package my, Inside this package, we define a class My Bean. The class define a newly created instance of String class.
The next step is to create a JSP page. This JSP page uses My bean package . Let us go through the list of steps to be carried out to call a My bean class.
<jsp.useBean>Attributes used in use bean-
<jsp.set Property>
The <jsp:useBean> element contains a <jsp:setProperty> element that is used to sets property values in the Bean. The <set Property> is used to set Property values in various way like-
<jsp:get Property>
The <jsp:useBean>element contains a <jsp:getProperty> element that is used to return the value stored in the set property.
The Jsp page is saved as UseBean.jsp,To run Use Bean .jsp,we have to place this file inside TOMCAT HOME\webapps\Use Bean and start Tomcat. Once Tomcat is started, type the URL in the browser and run your application.
MyBean.java
package my; public class MyBean { private String name=new String(); public String getName() { return name; } public void setName(String name) { this.name = name; } } |
UseBean.jsp
<html>
|
Output of the program
Ads