wood burning stoves 2.0*
The moose likes JSP and the fly likes Is it possible to validate (check) filelds with JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Is it possible to validate (check) filelds with JSTL" Watch "Is it possible to validate (check) filelds with JSTL" New topic
Author

Is it possible to validate (check) filelds with JSTL

Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Hello everybody,

I know that the simple way to check fields of a form is with javascript. But I don't know if you also can doe that with JSTL.

If yes please an example.

Abu Romaysa
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
JSTL is server side stuff. it means that if some page has JSTL within it, it comes to client after doing all processing at server-side. and the client get a simple HTML page. similar to scriplets.

better do it with javascript on the client-side, and make sure to put validation at the server end as well. because never rely on just client-side validation.

cheers.
Chintan Zaveri
Greenhorn

Joined: Oct 27, 2008
Posts: 2
This one is old but I think, the question is still valid.

How can I validate form fields using JSTL?

I would like to remove all leading and trailing spaces and then perform validation such as:

1. Whether or not a parameter is empty
2. Whether or not a non-empty parameter has length X (e.g. 20 characters)
3. Whether or not the given email is a valid email (syntax-only)
4. Whether or not the given website URL is a valid URL (syntax-only)
5. Whether or not some field "abc" is checked.
6. Which of the given radio buttons are checked.
7. Whether or not there are any special characters in the given field (in such a case, I would like to give error)

I know this can be done using Javascript and Core Java and I am not interested in those solutions.

I did google for this before posting but couldn't find anything appropriate. Please let me know if I have overlooked something.

Thanks in advance and kind regards,

Chintan Zaveri.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Originally posted by Chintan Zaveri:
Please let me know if I have overlooked something.
You completely overlooked Adeel's answer.

JSTL tags are evaluated on the server long before the resulting HTML page is being sent to the browser. Please see this article to correct your understanding of how JSPs work.

I know this can be done using Javascript and Core Java and I am not interested in those solutions.
Think again.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
If you're after a pure Java solution, look for a MVC framework such as JSF or Struts. A decent MVC framework already ships with built-in validation techniques.

JSTL is just there to control the flow in JSP. Not for validation or so.

That said, for the best user experience, I would also add (yes, add) Javascript based validation, because this way the user will be saved from an extra request to the server side.
Chintan Zaveri
Greenhorn

Joined: Oct 27, 2008
Posts: 2
Bear Bibeault:

I didn't really miss Adeel's reply - I was just a little too dumb not to think over it. :-( Thanks for the excellent article! :-)

Bauke Scholtz: Thanks for the encouraging post! Will use Struts.

Well, I just said "I am not interested in JS or Core Java solution" because I wanted to learn how this could have been done in JSP - maybe, using JSTL.

I am using Javascript, too.

Regards,

Chintan.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You're welcome.
 
Consider Paul's rocket mass heater.
 
subject: Is it possible to validate (check) filelds with JSTL