Thanks for your reply. I have one html form. on action I am calling servlet page. That servlet page has certain calculation as per user input on html page. I want to validate all those user input before it go to calculation code. If there is missing value or something wrong input, then it should go back to pointing that filed. I am not getting how to do?
D. Ogranos
Ranch Hand
Joined: Feb 02, 2009
Posts: 181
posted
0
Take a look at the signatures of the servlet method you're using (probably doGet() or doPost()). You will see that it has parameters HttpServletRequest and HttpServletResponse. Through the HttpServletRequest you can access the values from your form, by using the getParameter() method: if a field in your form has the name "foo", you would call request.getParameter("foo") in the servlet to access it. Note that what you get from the method is a string, which you have to transform to the correct type. Then you can simply check if it has the expected value.
If the value is wrong, you forward back to the form page, by using the request.getRequestDispatcher().forward() method. You should also put an error message in the request with request.setAttribute(), to display on the form page so the user knows what's wrong.
Kasparov Patel
Greenhorn
Joined: Jan 23, 2012
Posts: 28
posted
0
Hello D. Ogranos,
Thanks for your really very good explanation.
Kasparov Patel
Greenhorn
Joined: Jan 23, 2012
Posts: 28
posted
0
How can I send alert message from servlet to html file?
to do validation on server side you have access to HttpRequest object and can use getParameter(String str)
another way is to check user input inside html(better option)
as your html page is accepting the user input, you can make your html page to do validation using the javascript.
Tim Moores
Rancher
Joined: Sep 21, 2011
Posts: 2329
posted
0
naveen yadav wrote:as your html page is accepting the user input, you can make your html page to do validation itself before request is send to servlet. you can do this by using the javascript inside your html.
That's insufficient; all validations done in JavaScript also need to be done on the server.
See my reply in the other topic where you asked this question; you really should not post the same question multiple times.
Bear Bibeault
Author and opinionated walrus
Marshal