Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
JSP
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
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. 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.

                          

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

Latest Searches:
java string
html:button jsp exampl
<resultset
hyperlink in JSF
Internationalization u
use jsf in javascript
Image with mouse drag
input in array java
PHP File Manipulation
update Excel raw by ra
architecher of struts
Error
source code for JTable
passing values from js
multiple log files
spring aop
struts portlet
sql eclipse
Read and update Excel
Connecting to the MS s
netbeans jsp jdbc
input charaters in arr
file upload examplein
dynamically Textbox ar
Applet event button
select a row of data t
Error handling in stru
Date in JSP
DataBase Security
Textarea
make a frame in swings
tuxedo
Servlet Example To Dis
java program to read t
struts2 gwt
jsp bean
Dreamweaver Migrating
factorial no.java scri
dynamic table
get Numeric Value
drill down in jfree ch
dynamic array value
JSP,J2EE PROJECT
Photoshop Effects Abst
Janino -- an Embedded
requestDispatcher
java programm for arra
PHP Database Related m
ejb3.0 example, jboss
the program will count
servlet and ajax
interfaces
Two Dimensional Array
match Date Examples
pagination in jsp
Photoshop Text Effects
looping
breakà¹?à¸?à¸??Ã
java date compare exam
give me some java pro
Combattons la programm
reading excel file usi
Photoshop Drawing 3D P
jdbc sample
finding max min array
axis 2
scroll bar
menu
swings
Database MS Access Dat
how to pass same varia
servlet
J2ME
how to retrieve image
max length 500 chars
struts2 checkbox
jsp bean get property
charts in struts
Connection Pooling cod
Uncoloring part of col
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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 | 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.