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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Implementing Bean with script let in JSP 
 

This application illustrates how to create a bean class and how to implement it with script let of jsp for inserting the data in mysql table.

 

Implementing Bean with script let in JSP

                          

This application illustrates how to create a bean class and how to implement it with script let of jsp for inserting the data in mysql table.

In this example we create a jsp page for taking the user name to insert in the database table. The bean.java class is used to fire the insert query and create the setter and getter method to set and get the value which come from jsp page.

 

 

The complete application is as follows:

 

 

Source Code of jspBean.jsp 

<%page language="Java" import="java.sql.*" %>

<html>

<head><title>JSP with Javabeans</title></head>

<body>
  <h1>JavaBeans example</h1>

  <form name="form1" method="POST">
    
    Your Name:<input type="text" name ="message"> <br>
    
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type = "submit" value="Submit">

    <jsp:useBean id="sample" class="myexample.bean" scope="request">
      <jsp:setProperty name="sample" property="*"/>

           <br>
  <b>Welcome <jsp:getProperty name="sample" property="message"/></b>
    </jsp:useBean>



  </form>
  <% sample.insert();%>
</body>

</html>

 

Source Code of bean.java 

package myexample;

import java.io.*;
import java.sql.*;
 
public class bean {
  private int msgid;
  private String message;
    private Connection connection=null;
    private ResultSet rs = null;
    private Statement st = null;
  String connectionURL = "jdbc:mysql://localhost:3306/test";

  public bean() {
    try {
      Class.forName("com.mysql.jdbc.Driver");
      connection = DriverManager.getConnection(connectionURL, "root""root")
    }catch(Exception e){
      System.out.println("Exception is ;"+e);
    }
  }  

  public void setmsgid(int msgid){
    this.msgid = msgid;
  }

  public int getmsgid(){
    return (this.msgid);
  }

  public void setmessage(String message){
    this.message = message;
  }

  public String getmessage(){
    System.out.println("Message: "+message);
    return (this.message);
  }

  public void insert(){
    try{
      if(message!=null)
      {
      String sql = "insert into message(message)values('"+message+"')";
      Statement s = connection.createStatement();
      s.executeUpdate (sql);
      s.close ();
      }
    }catch(Exception e){
      System.out.println("Exception is ;"+e);
    }
  }
}

Download Complete Source Code

                          

» View all related tutorials
Related Tags: java c oop jsp io user word loop iteration ip page numbers key value number state this ai oo js

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