This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes Validation in JSP. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Validation in JSP." Watch "Validation in JSP." New topic

Validation in JSP.

Ram Kas
Ranch Hand

Joined: Jul 26, 2006
Posts: 83
I have a form with 3 fields in a form, UserName, City, Country. Length of each field should not exceed 10 characters. If it exceeds it, the page should be reloaded with error message on the same line of the text box.

Can anybody tell me how I can do it?
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
<input type="text" maxlength="10" name="text1">

User maxlenght attribute, it will not allow user to enter 11th character at first place.

My blood is tested +ve for Java.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60783

Unless a malicious user writes his own form to submit to your server.

Point is, client-side validation should never be trusted.

Yes, go ahead and add the maxlength attribute -- that's good for users since they cannot enter too many characters. But also check the length when the code is submitted.

In fact, validation should occur at every layer in the app in case someone is trying to spoof the upper layers. It also makes your code more robust and re-usable.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
subject: Validation in JSP.
Similar Threads
How to avoid validation if request was done by GET method?
form inside a from
How to use Two Action forms into one ActionClass?
Servlets inJSP
How to carry the values to the form