File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where to validate username password in struts

 
Rajendra Prakash
Ranch Hand
Posts: 293
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 665
4
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check it in validate() method, thats why this method is used..
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 293
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when to use Actionform's validate() . For which situation we can use validation.xml and validator-rules.xml
 
Prasad Krishnegowda
Ranch Hand
Posts: 665
4
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
Android AngularJS Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 293
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic