This action let you use java bean in a JSP page. This action instantiates or locates a Bean with a specific name and scope.
Syntax :
<jsp:useBean |
This usually means "instantiate an object of the class specified by class, and bind it to a variable with the name specified by
id".
Gives a name to the variable that will reference the bean. A previous bean
object is used instead of instantiating a new one if one can be found with the
same id and scope.
Indicates the context in which the bean should be made available. There are four possible values:
page, indicates that the bean is only
available on the current page (stored in the PageContext of the
current page).application
indicates that it is available to all pages that share the same ServletContext.'ava.beans.Beans.instantiate' method, and gives the Bean the type
specified in type. The value of 'beanName 'is either a
package and 'class name' or an 'Expression' that evaluates to a package and
class name, and is passed to 'Beans.instantiate'. The value of
type can be the same as 'beanName', a 'superclass' of
'beanName', or an interface implemented by 'beanName'.
String parameter :|
< HTML><head> <TITLE>JavaBeans in JSP</TITLE> <meta http-equiv="Content-Language" content="en-us"> <style type="text/css"> .style1 { border: 2px solid #0000FF; background-color: #CCFFFF;} </ style></ head>< BODY>< table class="style1" style="float: CENTER" align="center"> <tr> <td style="width: 430px; height: 38px"> <h3><strong>EXAMPLE OF JSP:USEBEAN STANDARD ACTION</strong></h3> </td> </tr></ table>< P>< jsp:useBean id="test" class="foo.usebeanexample" />< jsp:setProperty name="test" property="message" value="Hello ANKIT" />< center><H1>Message:< jsp:getProperty name="test" property="message" /></ H1></center></ BODY></HTML> |
Given below is the code for the bean used in the "usebean.jsp" :
usebeanexample.java
|
package foo;public class usebeanexample { private String message = "No message specified"; public String getMessage() { return(message);}public void setMessage(String message) { this.message = message;} } |

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.