Describing the useBean Action Tag:

The <jsp:useBean> action tag is used to instantiate a java bean, or to locate an exisiting bean instance, and assign it to variable name or id. Bean is a reusable component which mostly contains the setter and getter values, we also called it as mutators. We can also specify the life time of the object by giving it a specific scope. The <jsp:useBean> action tag ensures that the object is available, with the specified id, in the appropriate scope as specified by the tag.

Syntax for it is: <jsp:useBean attributes>
[body content]
</jsp:useBean>

E.g: <jsp:useBean id="regform" class="RegForm.RegForm" scope="session"/>

Attributes of the <jsp:useBean> Tag:

For declaring the bean in JSP we follow the following steps:

EXAMPLE:

RegForm.java:

package RegForm;

public class RegForm implements java.io.Serializable{
private String uname,,re,email,fn,ln,address;
public void setUserName(String s){uname=s;}
public void setword(String s){=s;}
public void setReword(String s){re=s;}
public void setEmail(String s){email=s;}
public void setFirstName(String s){fn=s;}
public void setLastName(String s){ln=s;}
public void setAddress(String s){address=s;}


public String getUserName(){return uname;}
public String getword(){return ;}
public String getReword(){return re;}
public String getEmail(){return email;}
public String getFirstName(){return fn;}
public String getLastName(){return ln;}
public String getAddress(){return address;}
}

RegProcess.jsp:

<%@page errorPage="Registration.html" %>
<html>
<body bgcolor="skyblue">
<jsp:useBean id="regform" class="RegForm.RegForm" scope="session"/>
<jsp:setProperty name="regform" property="*"/>
<form action="RegProcessFinal.jsp" ><pre><b>
First Name:<input type="text" name="first-name"/>
Last Name :<input type="text" name="last-name"/>
Address :<input type="text" name="address"/>
<input type="submit" value="Register"/>
</b>
</pre>
</form>
</body>
</html>

ViewRegistrationDetails.jsp:

<jsp:useBean id="regform" class="RegForm.RegForm" scope="session"/><jsp:useBean id="regform" type="RegForm.RegForm" scope="session"/>
<%@page errorPage="Registration.html" %>
<html>
<body bgcolor="cyan">
<pre>
<b>User Name :</b><jsp:getProperty name="regform" property="userName"/>
<b>word :</b><jsp:getProperty name="regform" property="word"/>
<b>Email_Id :</b><jsp:getProperty name="regform" property="email"/>
<b>First Name :</b><jsp:getProperty name="regform" property="firstName"/>
<b>Last Name :</b><jsp:getProperty name="regform" property="lastName"/>
<b>Address :</b><jsp:getProperty name="regform" property="address"/>
</pre>
</body>
</html>

Registration.html:

<html>
<body bgcolor="cyan">
<form action="RegProcess.jsp"><pre><b>
UserName :<input type="text" name="userName"/>
word :<input type="word" name="word"/>
Reword :<input type="word" name="reword"/>
Email Id :<input type="text" name="email"/>
<input type="submit" value="Register"/>
</b></pre></form>
</body>
</html>

RegProcessFinal.jsp:

<%@page errorPage="Registration.html" %>
<jsp:useBean id="regform" class="RegForm.RegForm" scope="session"/>
<jsp:setProperty name="regform" property="firstName" param="first-name"/>
<jsp:setProperty name="regform" property="lastName" param="last-name"/>
<jsp:setProperty name="regform" property="address" />
<html>
<body bgcolor="pink">
<pre>
Your details are valid
<a href="ViewRegistrationDetails.jsp">CLICK</a>to view and confirm
</pre>
</body>
</html>

OUTPUT:

Registration.html:

html.gif

RegProcess.jsp:

regprocess.gif

RegProcessFinal.jsp:

regfinal.gif

RegDetail:

detail.gif