File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes validation on serverside Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "validation on serverside" Watch "validation on serverside" New topic

validation on serverside

Saptarshi Chakraborty

Joined: Jul 26, 2007
Posts: 23
Hi friends'

I want to implement validation routine in serverside.I have already implemented it as a client side validation.I have
3>and a jsp page in which
In the form tag I have written onsubmit="return validateAddressForm(this);
<html:javascript formName="AddressForm"/>
This generates the client side javascript for client side validations in the fields like name,password etc.
How could I implement the same validation routine in the server side. Is there any change that I have to make in the form bean. and what I have to do in my jsp page.
Kishore Kumar
Ranch Hand

Joined: Oct 15, 2007
Posts: 71
In your frombean, implement validate method and validate all the desired fields.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
All the validation rules you defined in a validation.xml file will apply to both client-side and server-side validation. Even when client-side validation is turned on, Struts Still does Server-side validation. There's nothing you have to do to turn that on. It's done automatically. All you have to do is make sure your ActionForm extends ValidatorForm and add an <html:errors /> tag to your JSP so that there is a place for server-side errors to be displayed.

Note that when client-side validation is enabled, server-side validation is really just a backup plan, as the client-side validation should pick up any errors before the request is even submitted to the server. However, because a user can disable JavaScript on the browser, it's always safer to do server-side validation also just in case.

Consultant, Sima Solutions
I agree. Here's the link:
subject: validation on serverside
It's not a secret anymore!