• 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

Is it possible to validate (check) filelds with JSTL

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.
 
reply
    Bookmark Topic Watch Topic
  • New Topic