This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Unable to control page transitions - Javascript and Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Unable to control page transitions - Javascript and Servlet" Watch "Unable to control page transitions - Javascript and Servlet" New topic
Author

Unable to control page transitions - Javascript and Servlet

Prashil Virgincar
Greenhorn

Joined: Aug 21, 2012
Posts: 8
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

Joined: Jan 10, 2002
Posts: 60740
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Prashil Virgincar
Greenhorn

Joined: Aug 21, 2012
Posts: 8
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

Joined: Jan 10, 2002
Posts: 60740
    
  65

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

    Joined: Aug 21, 2012
    Posts: 8
    Thanks a ton ! That helped.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Unable to control page transitions - Javascript and Servlet
     
    Similar Threads
    Java and JavaScript functions
    Hot to access Form values before submit to action