Baran Topal

Baran Topal


May 2024
M T W T F S S
« Feb    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories


Some silly java bean example from bean to jsp

baranbaran

A javabean is a class that conforms to  certain standard conventions. That way the Servlet container can find your data. You can download the specification at
http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html
For a Servlet container, the javabean must be in a package.

package rrz;
import java.util.Random;
public class IdBean implements java.io.Serializable
{
 private String randomId = null;
 public String getRandomId(){
 //return randomId; // this would be the standard line 
 //you can substitute your own code here or call your utility class
 return Integer.toString(new Random().nextInt());
 }
 public void setRandomId(String randomId){
 this.randomId = randomId;
 }
}

and example jsp is as follows:

<jsp:useBean id="myBean" class="rrz.IdBean" />  value="${myBean.randomId}"