JSP Tutorials

jsp:useBean action tag
Previous Home Next
adplus-dvertising

jsp:useBean action tag

This tag is used to locate a bean class when bean object is created but if object of bean is not created, it is called instantiates the bean.

Syntax used

    <jsp:useBean id= "instanceName" scope= "page | request | session | application"   
    class= "packageName.className" type= "packageName.className"  
    beanName="packageName.className | <%= expression >" >  
    </jsp:useBean>  

    <jsp:useBean id= "instanceName" scope= "page | request | session | application"   
    class= "packageName.className" type= "packageName.className"  
    beanName="packageName.className | <%= expression >" >  
    </jsp:useBean>  

Example

Sava as Calculator.java
    package com.javatpoint;  
    public class Calculator{  
    public int cube(int n){return n*n*n;} 
    }  

    package com.javatpoint;  
    public class Calculator{  
    public int cube(int n){return n*n*n;}  
    }  
index.jsp
    <jsp:useBean id="obj" class="com.javatpoint.Calculator"/>  
    <%  
    int m=obj.cube(5);  
    out.print("cube of 5 is "+m);  
    %>  

    <jsp:useBean id="obj" class="com.javatpoint.Calculator"/>  
    <%  
    int m=obj.cube(5);  
    out.print("cube of 5 is "+m);  
    %> 
Previous Home Next