Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can serveltfileter be used for serverside validation

 
Rauhl Roy
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

can serveltlister or servelet filter be used for server side validations?

May i know what should i do?
thanks and regards,
venkat.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64828
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While you could use a filter for server-side anything, including validation, I don't think it's a good idea. Filters are best used for purposes that are orthogonal to the servlets that will be running. In other words, if the servlets depend upon the filter being run in order to execute properly, such as with the validation idea, then what good is it to take that logic out of the servlet and put it in a filter? There are much better ways to share common code (if that's the idea behind it).

I do not know what a servletlister is.
 
Rauhl Roy
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot for your reply, i did not mean servletlistner i'm sorry, i did mean, listeners in servlets can be used for server side validations?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64828
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, listeners...

Well, not really. What type of listener were you thinking of?
 
Rauhl Roy
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even i do not know, but i just want to know, my scenario is that if server side validation gives any error message we are supposed to send a notification or a message to client some times technical staff and sometimes to the server.

please let me know if you are aware of this.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64828
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As listeners are triggered on events that are usually outside the normal request-response cycle, they are unsuitable for this purpose.

Do you have a specific validation need that you are trying to solve that can't simply be handled in the servlet?

Remember, with very few exceptions, simple is better.
 
Rauhl Roy
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you mean servlets can validate anything, so i dont have to think of filters and all?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly do you want to validate? The logged in user? Or certain request headers? Or the submitted input values?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64828
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Filters are good for "out of band" things like authentication, or setting no-cache headers. They should not be used for doing "in-line" things that are better and easier to handle in the servlet itself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic