File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Best way to do form input ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Best way to do form input ?" Watch "Best way to do form input ?" New topic

Best way to do form input ?

Phil Chuang
Ranch Hand

Joined: Feb 15, 2003
Posts: 251
I've done around 3 different web applications now, and all 3 have handled JSP form input & field validation in different ways - so the question I pose to you all is, what is the best way?
Given these constraints:
1) clean & simple design
2) easy linking between the JSP form fields and the bean fields (loading)
3) easy way to do validation
I would guess that some degree of reflection would be used to automate the field processing.
So here's my current take on things:
Common JavaBean, but with the addition of a set of validation methods (get/set/validate) that take in String input and validate it against the field type. I'm planning on naming the fields in the JSP exactly as the field name in the bean, although that might run into problems if the input uses more than one bean and they have the same fieldnames. Once the form is submitted, go through all the input parameters calling the validate & set methods for the appropriate fields.
how's that sound?
I agree. Here's the link:
subject: Best way to do form input ?
It's not a secret anymore!