File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Email Address Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Email Address Validation" Watch "Email Address Validation" New topic
Author

Email Address Validation

Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Hello Ranchers ,

I have been going good with Struts these days and am loving the way its making my life easier. This time the requirement is about email address validation. No , I am not talking about Javascript Validation of Email or Server Side Validation in ActionForm for Email. The requirement is this.

The user would come on the Page and enter an email address and complete the registration. It gets saved in the database. So far so good. Now , The next time other user comes and tries to key in the same email address, It should goto DB and check if the Email Address already exists. If it does , It should give error to the user saying "Sorry, Email Address already exists in DB, Try with Some other Email Address"..

I am confused as to how to put this into reality ?

Would appreciate if someone sheds light on this.

Thanks in advance.

Yogendra N Joshi.


Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
samir ware
Ranch Hand

Joined: Jul 27, 2005
Posts: 192
Hi Yogendra ,
As far as your screnio goes, yours is the server side validation . The stright forward way of doing this is access the email addresses of all the clients in the vector(if you want application to be thread safe) or in a arraylist.
You can improve the performance thereby stoirng all the values in the databse in ascendind or descending order and making the use of well known algorithums for making the search .
Once you have all the data with you in the arraylist or vector.you can compair it with the newly added e-mal address
I hope this should work fine for your case
Regards
Samir Ware
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I wouldn't recommend the Vector or ArrayList approach, mainly because it doesn't scale. It's fine for 100 users, but it's not fine for 2 million users.

I'd sugget creating a Data Access object with a method that runs a query against the database and returns true if the address exists and false if it doesn't.

You would then instantiate this object and call its method from an Action class. If the method returns true, you would use the ActionErrors object to send a message back to the JSP. Your code would look something like this:



Then in your JSP, you use the <html:errors/> tag to display the message.


Merrill
Consultant, Sima Solutions
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
Originally posted by Merrill Higginson:
I wouldn't recommend the Vector or ArrayList approach, mainly because it doesn't scale. It's fine for 100 users, but it's not fine for 2 million users.

I'd sugget creating a Data Access object with a method that runs a query against the database and returns true if the address exists and false if it doesn't.

You would then instantiate this object and call its method from an Action class. If the method returns true, you would use the ActionErrors object to send a message back to the JSP. Your code would look something like this:



Then in your JSP, you use the <html:errors/> tag to display the message.



Hello Merrill and Samir ,

I have successfully implemented and it worked perfect.

Thanks Again.

Yogendra Joshi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Email Address Validation