Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet doubt

 
Raja seemakurthi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how one can validate the HTML form fields before submitting them to database.
my scenario is:-

In html page,there are some form fields like name,password,age,email and one submit button also.When i click on submit button all the form fields are supposed to get validated thru java-script function.In the form action="/FDTest.do" tag all the details entered by user are supposed to store in Database for that, code is written in 'FDTest.java' file.

And in 'web.xml' file
is given.

any thing is wrong in this code?

and is there any other way to map the url-pattern with servlet class?
and is it necessary to give the same string at form action="XXX" and url-pattern XXX.

please let me know that as soon as possible.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes something is wrong


In order to avoid mysterious errors, ALL classes used in servlets should be in packages. Naturally the location of .class files must reflect the package name.
 
Raja seemakurthi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
even i tried class name with the package name also.
but i want to know that is it possible to validate the data entered by user and then forward the data to java class to submit into the database? by clicking on submit button. and form action="FDTest.do" is it ok? or need to change it?
 
Ashok Kumar Babu
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your case, I think you want to validate in JavaScript. Is nt it? Then you should make a call to a JavaScript method first, Validate all your Form fields there and then submit the form to the Servlet.
[ April 07, 2008: Message edited by: Ashok Kumar Babu ]
 
Raja seemakurthi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, i mean that.once all fields are validated then only the data is supposed to be submitted to database.

but my doubt is....... what should be written in form action attribute? and what should be the form field for submit, is it submit button or simply a button? then what should be the java-script method? is it onsubmit() or onclick()? could you help me to get solution?

one more thing i required is, how both actions will be done at a time? like..clicking on submit-button/normal button and sending the details through form action to other java class. how both actions can be done at a time?
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really (!) shouldn't rely on client-side validation of input.
There's nothing wrong with validating input client-side to promote fast feedback to the user. However, in terms of security client-side validation of input is a BIG no-no, because an attacker can easily bypass these checks. You should always validate (user) input server-side.
[ April 07, 2008: Message edited by: Jelle Klap ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jelle Klap:
You really (!) shouldn't rely on client-side validation of input.
There's nothing wrong with validating input client-side to promote fast feedback to the user. However, in terms of security client-side validation of input is a BIG no-no, because an attacker can easily bypass these checks. You should always validate (user) input server-side.

Jelle Klap is 100% correct. Print out this post and put it up on your wall.

Data needs to be validated on the server regardless of whether it was already validated on the client or not.
[ April 07, 2008: Message edited by: Bear Bibeault ]
 
kejiya palaparthi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi raj

You have asked one doubt like is it both actions are working at the same time , i.e onsubmit and onclick

No , both are not work at the same time , either onsubmit or onclick will do action .

If suppose you want to use onsubmit you just keep like this input type = "submit" for onclick input type="button"

If you are using action so you have to use onsubmit only then only you are form fields will be validated at that time onclick will not use as my understand why I am saying this i have faced the same problem .

I hope You can understand onsumbit="return scriptmethod();"

thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic