*
The moose likes JSP and the fly likes javabean problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "javabean problem" Watch "javabean problem" New topic
Author

javabean problem

Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

here is my Customer.class

package estore;

import java.sql.*;
import java.io.*;
import java.util.*;


public class Customer
{
private String FName;
private String LName;
private String Address;
private String City;
private String Country;
private String Zipcode;
private String Telephone;
private String EMail;

private int Customer_ID;

public Customer(int Customer_ID,String FName,String LName,String Address,String City,
String Country,String Zipcode,String Telephone,String EMail)
{
this.Customer_ID = Customer_ID;
this.FName = FName;
this.LName = LName;
this.Address = Address;
this.City = City;
this.Country = Country;
this.Zipcode = Zipcode;
this.Telephone = Telephone;
this.EMail = EMail;
}

public int getCustomer_ID()
{
return Customer_ID;
}

public void setCustomer_ID(int id)
{
Customer_ID = id;
}

public String getFName()
{
return FName;
}

public void setFName(String fn)
{
FName = fn;
}

public String getLName()
{
return LName;
}

public void setLName(String ln)
{
LName = ln;
}

public String getAddress()
{
return Address;
}

public void setAddress(String addr)
{
Address = addr;
}

public String getCity()
{
return City;
}

public void setCity(String cit)
{
City = cit;
}

public String getCountry()
{
return Country;
}

public void setCountry(String countr)
{
Country = countr;
}

public String getZipcode()
{
return Zipcode;
}

public void setZipcode(String zc)
{
Zipcode = zc;
}

public String getTelephone()
{
return Telephone;
}

public void setTelephone(String tele)
{
Telephone = tele;
}

public String getEMail()
{
return EMail;
}

public void setEMail(String em)
{
EMail = em;
}

private boolean ValidateFields()
{
//String FName = Customer.getFName();
//String LName = Customer.getLName();
//String Address = Customer.getAddress();
//String City = Customer.getCity();
//String Country = Customer.getCountry();
//String Zipcode = Customer.getZipcode();
//String Telephone = Customer.getTelephone();
//String Email = Customer.getEMail();

if ((FName.equals("")) | (LName.equals("")) | (Address.equals("")) | (Country.equals("")) |
(Telephone.equals("")) | (EMail.equals("")) | (City.equals("")) | (Zipcode.equals("")))

return false;
else
return true;

}

private void CreateCustomer() throws ClassNotFoundException,SQLException,IOException
{
Class.forName("org.gjt.mm.mysql.Driver");
Connection con = null;
try
{
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/e_store");

Statement stmt = con.createStatement();

String insertCustomer = "Insert into Customers (Customer_ID,FName,LName,Address,Country,City,Telephone,Zipcode,EMail) " +
"Values( 'm + 1'," + "'" + FName + "','" + LName + "','" + Address + "','" + Country + "','" + City + "','" + Telephone +
"'" + FName + "','" + EMail + "');";

stmt.executeUpdate(insertCustomer);
stmt.close();
}
finally
{
if (con != null)
con.close();
}
}

}




and here my jsp page that uses the class

<%@ page import="java.util.Date, java.sql.*, java.util.*" %>
<%@ page contentType="text/html; charset=iso-8859-7" %>
<jsp:useBean id="newcust" class="estore.Customer" scope="page"/>
<jsp:getProperty name="newcust" property="ValidateFields"/>
<jsp:getProperty name="newcust" property="CreateCustomer"/>

"<"html">"
"<"head">"
"<"title">"���� ������� -- Registration"<"/title">"
"<"/head">"
"<"body">"

"<"%
if (request.getParameter("Submit") != null)
{
if (ValidateFields())
{
CreateCustomer();
}
}
%">"


Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

tomcat returns that it didnt find the package estore
the .class files are in the class folder
what is the problem???
evan theon
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
when you use your own package to store your classes you have to create a directory with the exact name with the package inside the class directory, for instance :

you have to create : Tomcat/WEB-INF/classes/estore/
and store your Customer.class in there

try it and let me know ho's it going...
regards
Nitin Jawarkar
Ranch Hand

Joined: Dec 18, 2004
Posts: 79
hello friend,

You create your own directory like estore, so now put it under WEB-INF/classes/estore and then call it in your JSP page, hope it will work fine.


Cheers<br />Nitin
Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

It finds the class finally
but know there is another problem
tomcat returns an error --> cant find information on ValidateFields
how do i use the methods of the .class file?
is it right?

thnx!!
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Aris ,

didn't see full code but accessibility modifier of ValidateFields is private, change it to public it should solve your problem.

thanks


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Shailesh Chandra:
Aris ,

didn't see full code but accessibility modifier of ValidateFields is private, change it to public it should solve your problem.

thanks


You'll also want to use JavaBean naming conventions for your methods.
Change ValidateFields to getValidateFields or isValidateFields. Then access with "property="validateFields".

The useBean and getProperty tags are not really designed for calling utility methods. They are designed for reading properties from beans in an MVC pattern. The controller should be a servlet.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

i changed it to public but it gives me the same error!!
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Ben Souther:


You'll also want to use JavaBean naming conventions for your methods.
Change ValidateFields to getValidateFields or isValidateFields. Then access with "property="validateFields".

The useBean and getProperty tags are not really designed for calling utility methods. They are designed for reading properties from beans in an MVC pattern. The controller should be a servlet.
Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

how can i do what you are saying
im not a pro in jsp and i need some help on that
if you can give me an example or something
it will really help me

thnx
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Aris Doxakis:
how can i do what you are saying
im not a pro in jsp and i need some help on that
if you can give me an example or something
it will really help me
thnx


SimpleMVC at http://simple.souther.us uses jsp:useBean and jsp:getProperty tags in an MVC pattern.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Aris Doxakis:
how can i do what you are saying
im not a pro in jsp and i need some help on that
if you can give me an example or something
it will really help me
thnx


SimpleMVC at http://simple.souther.us uses jsp:useBean and jsp:getProperty tags in an MVC pattern.
Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

thnx i will study them
if i have any questions im sure they will be answered

thnx again
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javabean problem
 
Similar Threads
HTTP ERROR: 500
HTTP ERROR: 500
javabean problem
problem with MS Access and max
Servlet help