• Post Reply Bookmark Topic Watch Topic
  • New Topic

Form validation  RSS feed

 
Anu Pasricha
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I) What is the correct approach of programming.
1) Validating the form fields in the same servlet and call next page if correct.
or
2)calling next page using 'Form Action' and validating fields in next page and if anything wrong then redirecting to previous servlet.
II) Where (sites) can I find good study material for form validation etc. using servlet.
Thanx
Anu
 
Andy Bowes
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a standard and well-known issue with server-side Java programming. The typical design pattern that is used to handle this is the Model View Controller (MVC) pattern. Basically the 'front' controller (usually a servlet) receives all incoming HTTP requests and delegates the processing to the appropriate business object(s) depending upon the action being submitted/requested by the user.
The front controller will also determine the next screen that should be displayed to the user. This prevents a chain of dependancy occuring between servlets in the the application.
The most commonly used MVC framework used to create Java applications is Struts. It can be a bit daunting at first but it does a pretty good job of handling form-based application.
Hope this helps
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I) What is the correct approach of programming.
1) Validating the form fields in the same servlet and call next page if correct.
or
2)calling next page using 'Form Action' and validating fields in next page and if anything wrong then redirecting to previous servlet.

In my opinion, I would go with option (2). This will allow you to keep your responsibilities seperate .i.e. presentation(form page) from business(rules to determine valid input data) logic. If not, your presentation page may become full of business logic, which could make the presentation page less useable and maintainable. Like Andy stated the MVC is a very popular architecture, which is based on separation of responsibilities. There are plenty of resources on the internet that will give you all of the information you may need, not to mention the Struts project.
craig
 
bharat nagpal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my views, It depends on the application requirements.
The advantage of the first approach is good performance. The ability to validate the input on client side, is very important in some cases.
I have worked with both the appraoches. and in the first one I used .js files for validations
The second approach clearly seperates the designer from business logic.
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I personally use this pattern and I like it a lot.
http://www.javaworld.com/javaworld/jw-03-2000/jw-0331-ssj-forms.html
hope it helps
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!