• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to control page transitions - Javascript and Servlet

 
Prashil Virgincar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using Java Servlets and Javascript (application development environment is Eclipse Juno)
I have this web page (index.html) where I want to ensure that user enters all the fields correctly. If he/she does not enter something correctly, I am throwing an alert (tested by the Javascript function - associated with the Submit button). If the user does not enter the data correctly I want the index.html to stay and not transition.

Currently for debugging, I am taking the entered data and displaying it on the screen (using doGet() function). So, what is happening is even if user does not enter something correctly, the Servlet is being executed and the index.html transitions.

The application I am developing is as below:
1) User enters data
2) Data has to be written to a word document
3) Document has to be emailed to a particular email address

I am currently just developing the webpage.


Please advise.


Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64724
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prashil Virgincar wrote:Please advise.

About what? You haven't really asked a question.

If I had to guess, perhaps you are having trouble dealing with the server-side validation? If validation fails, you'd pack up the submitted values in the session and redirect back to the page (or page controller) with the form, filling in the values in the form elements using their value attributes.
 
Prashil Virgincar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

Sorry, I wasnt clear i guess.

I want to know how to stay on the same page (index.html) and not execute the servlet unless all the values on the form have been validated successfully. I validate them via a javascript function associated with the "submit" button.

Does this help ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64724
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do validation easily on the page prior to submission -- but you must also validate on the server as I have described as you can never be sure that client-side validation has occurred.

I use jQuery and its Validation plugin on my pages. But if you want to roll your own:
  • Create a submit handler for the form
  • Perform any validation in the handler
  • Return true to allow the form to submit, false to prevent submission
  •  
    Prashil Virgincar
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks a ton ! That helped.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic