Here's an example jsp followed by the bean . You may have to make some changes
to run in your environment , also need
to put the bean in the appropriate folder.
hope this gives you some direction
Santosh
JSP
<%@page import="hello.*;" errorPage="DisplayError.jsp"%>
<jsp:useBean id="DbBean" class="hello.DeveloperBean"/>
<html>
<head>
<h1>New User Registration</h1>
<body bgcolor="grey" text="blue" >
<p>
<br>
<form name="registration" action="CreateUser.jsp">
<pre>
LoginId <input type =text name="loginid">
Password <input type =password name="password">
First Name <input type =text name="firstname">
last name <input type =text name="lastname">
Company <input type =text name="companyname">
StreetAddr <input type =text name="streetaddress">
City <input type =text name="city">
State <input type =text name="state">
Zip <input type =text name="zip">
Phone <input type =text name="phone">
</pre>
<Input type = submit name="create" value="Create" >
<Input type=Reset>
<input type=button value="Back To Home Page" onClick="window.history.back()">
</form>
<%
if ( request.getParameter("create")!=null)
{
String btnvalue = request.getParameter("create");
String loginid = request.getParameter("loginid");
if ( btnvalue.equals("Create"))
{
if ( DbBean.exists(loginid))
{
out.println("User Already Exists");
}
else
{
%>
<jsp:setProperty name="DbBean" property="password"/>
<jsp:setProperty name="DbBean" property="firstname"/>
<jsp:setProperty name="DbBean" property="lastname"/>
<jsp:setProperty name="DbBean" property="companyname"/>
<jsp:setProperty name="DbBean" property="streetaddress"/>
<jsp:setProperty name="DbBean" property="city"/>
<jsp:setProperty name="DbBean" property="state"/>
<jsp:setProperty name="DbBean" property="zip"/>
<jsp:setProperty name="DbBean" property="phone"/>
<%
if (DbBean.setLoginId(loginid))
{
out.println("User "+loginid+" created");
}
}
}
}
%>
</body>
</head>
</html>
Bean
package databean;
import java.sql.*;
public class DbBean {
static Connection con;
static String dsnName ="jdbc:odbc:yourdsnname" ;
public DbBean() throws ClassNotFoundException,SQLException {
}
public static Connection getDBConnection() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(dsnName);
}catch(ClassNotFoundException e){
}catch(SQLException e){
}
return con;
}
public String[] getResultSet(String query) throws SQLException {
ResultSet rs1 = null,rs2=null;
int i=0,counter=0;
String[] name = null;
Statement stmt1=null,stmt2=null;
try {
stmt1 = DbBean.getDBConnection().createStatement();
rs2 = stmt1.executeQuery(query);
while(rs2.next()){
counter++;
}
stmt2 = DbBean.getDBConnection().createStatement();
rs1 = stmt2.executeQuery(query);
name = new String[counter];
while(rs1.next()) {
name[i] = new String();
name[i] = rs1.getString(1);
i++;
}
}
catch(SQLException e){
e.printStackTrace() ;
}
return name;
}
public int getUpdataInsertDeleteCount(String query) throws SQLException {
int count=0;
Statement stmt=null;
try {
stmt = DbBean.getDBConnection().createStatement();
count = stmt.executeUpdate(query);
}
catch(SQLException e){}
return count;
}
}
Sushil Singh <[EMAIL PROTECTED]> on 09/18/2000 03:13:56 PM
Please respond to A mailing list about Java Server Pages specification and
reference <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc: (bcc: Santosh Daryani/IT/Aon Consulting)
Subject: JSP:<BEAN> Examples
Hi,
I have never used any beans in JSP, if anybody can provide me a simple
JSP which uses a BEAN (Database bean etc), in order to understand the
concept/advantages. it will be highly appreciated.
Thanks.
Sushil
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets