• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Form validation

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic