• 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

if condition in servlet

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have created a program to take a name and list of books from user and my code calculate the total amount of book whatever he selected and gives all books name selected and total amount of books to output.but
my code works even user doesn't give her/his name so
i want to create condition that when user will not give her/his name then my program will not work and gives proper message to user "please enter your name".

but i doesn't understanding that what did i give condition .i have uncommented a if condition and my else block is at last




 
Ranch Hand
Posts: 277
Oracle Spring Flex
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you check it in server side. You probably check it in client side and prevent user from submitting the form to the server.

 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ashwin Sridhar wrote:Why do you check it in server side. You probably check it in client side and prevent user from submitting the form to the server.


Client-side validation can never be relied upon. You can do it if you want, but you have to do it server side as well.
 
Ranch Hand
Posts: 163
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:Client-side validation can never be relied upon.



Why is that?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bill Clar wrote:Why is that?


Because it can always be circumvented. For example, if you're using Javascript validation it can be turned off. Or they can modify the Javascript on the fly. Or they can avoid using a web browser at all and just sent custom HTTP messages straight to your server.

You have no control over the client at all, so you can't make any assumptions about it. Client-side validation can be great for usability, but if it's for security or application integrity you have to do it server side.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And unless you are writing a very simple web application, you shouldn't do the validation in a servlet either. The servlet should delegate that responsibility to some other class. Your business logic should not rely on having a servlet to validate input data. That will couple your business logic too tightly to the delivery mechanism and that's not a good thing. It also makes your logic more difficult to test.
 
Bill Clar
Ranch Hand
Posts: 163
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:Because it can always be circumvented. For example, if you're using Javascript validation it can be turned off. Or they can modify the Javascript on the fly. Or they can avoid using a web browser at all and just sent custom HTTP messages straight to your server.

You have no control over the client at all, so you can't make any assumptions about it. Client-side validation can be great for usability, but if it's for security or application integrity you have to do it server side.



Never thought of it that way. Thanks for the insight, Matthew!
 
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your helpful suggestion guys. I am now taking care of server side validation as well.
 
Ritesh raushan
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


can anyone tell about what did i write in if condition.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A couple of things:

1. It would help if you fixed the indentation of the code that you provided. Right now, the indentation seems to be random and it makes your code even more unclear and harder to read. Few people will be inclined to clean up the code indentation for you so please ShowSomeEffort (←click)
2. In your own words, what do you want to check before executing some of this logic?
 
reply
    Bookmark Topic Watch Topic
  • New Topic