wood burning stoves*
The moose likes Servlets and the fly likes servlet doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet doubt" Watch "servlet doubt" New topic
Author

servlet doubt

Raja seemakurthi
Greenhorn

Joined: Jun 28, 2007
Posts: 17
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.


Thanks,
Raja
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
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

Joined: Jun 28, 2007
Posts: 17
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

Joined: Jul 25, 2006
Posts: 129
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 ]

Ashok<br /> <br />SCJP 91%<br />SCWCD 88%
Raja seemakurthi
Greenhorn

Joined: Jun 28, 2007
Posts: 17
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

Joined: Mar 10, 2008
Posts: 1753
    
    7

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 ]

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60780
    
  65

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
kejiya palaparthi
Greenhorn

Joined: Aug 29, 2007
Posts: 1
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: servlet doubt
 
Similar Threads
Servlet -Download Jar file
servlet not running from html file
Servlet not executing.
Calling a servlet from an HTML page
Tomcat error??