Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Use Of Form Bean In JSP 
 

This section gives you the best illustration about the procedure of handling sessions by using Java Bean.

 

Use Of Form Bean In JSP

                          

This section gives you the best illustration about the procedure of handling sessions by using Java Bean. This section provides the complete code of example with it's output particularly based on the module of an application. Following example helps you in developing your Java web based application. You can easily copy the code in you application for handling values or data using session through the Java Bean.

Program Summary:

There are three file have been used in the section for giving the complete soln of the topic "Handling Session From The Form Bean In JSP". These files are explained ahead particularly.

Here is the code of the getname.html file:

Following code has been used for constructing a form that takes some value like the name of the person, Email ID, Phone Number and the Age of the person. After submission the form it will refer to the savename.jsp file that will show the anchor tagged text "continue" and this file also sets all the value from the getname.html form to the Java Bean and proceed the value for the next operations with the session environment.

<HTML>
     <BODY>
          <FORM METHOD="POST" ACTION="savename.jsp">
          <center>
               <table bgcolor="#FFFFCC" cellpadding="0"cellspacing
="0" height="30%" width="50%">
                   <tr>
                      <td style="border-bottom-width:1px; border-
bottom-style:solid; border-bottom-color:#00000;"><B>User Name:<sup>
*</sup></B></td>
                      <td style="border-bottom-width:1px; border-
bottom-style:solid; border-bottom-color:#00000;"><INPUT TYPE=TEXT 
NAME=username SIZE="30"></td>
                   </tr>
                   <tr>
                      <td style="border-bottom-width:1px; border-
bottom-style:solid; border-bottom-color:#00000;"><B>Email Address:
<sup>*</sup></B></td>
                      <td style="border-bottom-width:1px; border-
bottom-style:solid; border-bottom-color:#00000;"><INPUT TYPE=TEXT 
NAME=email SIZE="20"></td>
                   </tr>
                   <tr>
                      <td style="border-bottom-width:1px; border-
bottom-style:solid; border-bottom-color:#00000;"><B>Phone Number:
<sup>*</sup></B></td>
                      <td style="border-bottom-width:1px; border-
bottom-style:solid; border-bottom-color:#00000;"><INPUT TYPE=TEXT
 NAME="pnumber" SIZE="11"></td>
                   </tr>
                   <tr>
                      <td style="border-bottom-width:1px; border-
bottom-style:solid; border-bottom-color:#00000;"><B>Age:<sup>*</
sup></B></td>
                      <td style="border-bottom-width:1px; border-
bottom-style:solid; border-bottom-color:#00000;"><INPUT TYPE=TEXT
 NAME=age SIZE="3"></td>
                   </tr>
                   <tr>
                      <td><INPUT TYPE="submit" value="Submit"/></td>
                   </tr>
               </table>
          </center>
          </FORM>
     </BODY>
</HTML>

Form created by the above code of the html file:


Code of the savename.jsp file.

<jsp:useBean id="user" class="roseindia.net.UserData" scope="session"/> 
<jsp:setProperty name="user" property="*"/>

<html>
     <body bgcolor="#ff99cc">
        <center>
        <a href="nextPage.jsp"><b>Continue</b></a>
        </center>
     </body>
</html>

Output for the above code of the savename.jsp file.



Following is the code of the Java Bean named UserData.java:

package roseindia.net;
public class UserData{
    String username;
    String email;
    String pnumber;
    int age;
    public void setUsername(String value){
         username = value;
    }

    public void setEmail(String value){
         email = value;
    }

    public void setPnumber(String value){
         pnumber = value;
    }

    public String getPnumber(){
         return pnumber;
    }

    public void setAge(int value){
         age = value;
    }

    public String getUsername(){
         return username;
    }

    public String getEmail(){
	 return email;
    }

    public int getAge(){
         return age;
    }
}

Code of the nextPage.jsp file:

<jsp:useBean id="user" class="roseindia.net.UserData" scope=
"session"/> 
<HTML>
     <BODY bgcolor="#FFFFCC">
       <center>
       <table border="0"  cellpadding="0" cellspacing="0" 
height="40%" width="40%">
          <tr>
             <td><FONT SIZE="4" COLOR="#333399">You have 
entered the following information:</FONT><BR></td>
          </tr>
          <tr>
             <td><B>Name:</B> <%= user.getUsername() %>
<BR></td>
          </tr>
          <tr>
             <td><B>Email:</B> <%= user.getEmail() %>
<BR></td>
          </tr>
          <tr>
             <td><B>Phone Number:</B> <%= user.getPnumber()
%><BR></td>
          </tr>
          <tr>
             <td><B>Age:</B> <%= user.getAge() %><BR></td>
          </tr>
       </table>
       </center>
     </BODY>
</HTML>

Output for the last file nextPage.jsp:

Above output shows the complete summary for the entered values in the getname.html constructed form.

Download complete example.

                          

» View all related tutorials
Related Tags: java c web com ide session data application io module copy help sessions sed output vi value using this id

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

Hello,

Just have one question about the code below,


package roseindia.net


can you please tell me the naming convention for this, and what it declares? can i name that anything?, its the only part i dont understand in this example, any help would be nice.

thank you
melisa

Posted by Melisa Mitchell on Monday, 09.8.08 @ 19:22pm | #78047

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.