This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes where to validate username password in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "where to validate username password in struts" Watch "where to validate username password in struts" New topic
Author

where to validate username password in struts

Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
I want to check username and password with database . where can i write validations, in Business class or validate()
method or action class.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 539

Check it in validate() method, thats why this method is used..
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
I want to check whether the username and pasword exists in database. How you can do this in ActionForm's validate() method . Is it possible
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
when to use Actionform's validate() . For which situation we can use validation.xml and validator-rules.xml
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 539

Rajendra Prakash wrote:I want to check whether the username and pasword exists in database. How you can do this in ActionForm's validate() method . Is it possible


yes, its possible.. its like normal validation only, by checking whether the entered user name is there in the database or not..

For which situation we can use validation.xml and validator-rules.xml


validator-rules.xml, is the place where, you specify all your validation rules, like numeric rule, alphanumeric rule.. etc and these rules are used in validation.xml..
Karthik Jayachandran
Ranch Hand

Joined: Feb 18, 2009
Posts: 88

Do basic validations like empty fields, invalid chars/length in validate() method of ActionForm.

In Action class, call the Business class' method to validate like

Writing database operations in ActionForm and Action classes are not recommended.

And in your business class, do the database implementation with the method returning a boolean or throwing a Exception.
If any error occurs, you can return the forward as


Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
can you give reason for "Writting database operations in ActionForm and Action classes are not recommended."
I need main reason for writting database operation in business class
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8935
    
    9

Because Struts is an implementation of the Front Controller pattern. It has little or nothing to do with business logic. Have a look here for more information (yes, it's in the 1.3 user guide, but the principal still applies).


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

Hello,

Consider your Action classes as the one(s) responsible for processing each client request. You can have different classes or even a hierarchy of classes for processing each particular request with all interaction to the persistence/data-access layer being routed though a DAO (an interface) and a DAOImpl (class implementing the persistence methods using the preferred approach, eg:- JDBC, Hibernate, JAXB, CSV etc.).

You provide a layer of abstraction as you can switch between different persistence strategies seamlessly and the remainder of the application would not be affected by this approach. The idea behind application design is to build a system which comprises of different components independent of each other and working in tandem to arrive at the required solution. It becomes all the more better if there is sufficient level of abstraction amongst these individual components so that you can freely make modifications/changes to any particular component and the other components as well as the system, on the whole, is not affected in any manner.

Does that answer your query?

Cheers,
Raj.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: where to validate username password in struts