Switch to full style
JSP Code Examples
Post a reply

use java beans with jsp form

Wed Jan 21, 2009 12:11 am

use Java beans with jsp(Java server Pages) form , here i have three code snippets , one for form and one for after submit form and one for java Bean class.

1. HTML Jsp form
Code:
<html>
    
    <
title>Codemiles :JSP Form with Java Beans </title>
    <
body>
        
        <
form action="afterindex.jsp" >
            
             
  <
p>First name: <input type="text" name="firstName" size=30>
  <
br>Last name: <input type="text" name="lastName" size=30>
  <
br>Email: <input type="text" name="email" size=30>

  <
p><input type="submit" name="Submit">
        </
form>
    </
body>
</
html>

 


2. After submit
Code:
<%@ page import="codemiles.Userentry"%>
<%@ 
page import="codemiles.Userentry"%>
<
jsp:useBean id="EntryBean" class="codemiles.Userentry" type="Userentry" scope="application" />
<
jsp:setProperty name="EntryBean" property="*"/>

<
html>
    
    <
body>
        <
b>
            
Your data has been submitted 
        
</b>
    </
body>
</
html


3. The Java Bean class :
Code:

 

package codemiles
;

/**
 *
 * @author codemiles Team
 */
public class Userentry {
    
String firstName;
    
String lastName;
    
String email;

    public 
void setEmail(String email) {
        
this.email email;
        
System.out.println(email);
    }

    public 
void setFirstName(String firstName) {
        
this.firstName firstName;
        
System.out.println(firstName);
    }

    public 
void setLastName(String lastName) {
        
this.lastName lastName;
        
System.out.println(lastName);
    }

    public 
String getEmail() {
        return 
email;
    }

    public 
String getFirstName() {
        return 
firstName;
    }

    public 
String getLastName() {
        return 
lastName;
    }
    




Post a reply
  Related Posts  to : use java beans with jsp form
 use of Java Beans in jsp     -  
 cmp entity beans     -  
 php login form (sign-in form)     -  
 Please help me in the form field     -  
 Feedback Form in php     -  
 Seconds Form to ( hh:mm:ss) (C++)     -  
 Get Form Numeric value     -  
 Upload Form     -  
 HTML registration form example     -  
 Form Validation Problem     -  

Topic Tags

Servlets/JSP