• Post Reply Bookmark Topic Watch Topic
  • New Topic

Removing business logic???

 
Moined Mogul
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I seem to have quite a bit of javascript within my JSP just doing simple authentication of user inputted data which will throw an alert to the user if something they entered does not meet the criteria I have defined.
I want to try and limit the business logic as much as possible within my JSP by getting rid of this javascript.
Could someone please suggest some alternative methods and give some examples of throwing something similar to a javascript alert if the user enters something that does not meet the criteria of the text box???
Thank you!
 
rostom aghanian
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ideal way of doing this when working with JSPs is by using JSP Beans. There are some tutorials and examples available on www.javaworld.com. Basically it involves posting the form data to the same page you are currently on, sending the user entered data to the server, validating it, and then returning an object (usually a hashmap) of error codes which are displayed if any errors were found. If no errors are found the JSP does a redirect to the next proper page.

Originally posted by Moined Mogul:
I seem to have quite a bit of javascript within my JSP just doing simple authentication of user inputted data which will throw an alert to the user if something they entered does not meet the criteria I have defined.
I want to try and limit the business logic as much as possible within my JSP by getting rid of this javascript.
Could someone please suggest some alternative methods and give some examples of throwing something similar to a javascript alert if the user enters something that does not meet the criteria of the text box???
Thank you!


------------------
rostom
 
Moined Mogul
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't that be quite costly though if you had several fields to validate....going to the server for validation every time???
 
Trevor Dunn
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is fairly costly because you have to make a round trip each time. I find the javascript solution much better myself for that particular reason. If your page is loaded with javascript then put the script code in an external final. This will clean up your page.
However in defence of the serverside validation, sometimes it is necassary if for any reason you are validating against data in a database for instance. But if you are just checking tomake sure the fields are filled out or contians just numbers or not letters, etc, then JavaScript is the better solution
Just my humble opinion
Trevor
[This message has been edited by Trevor Dunn (edited August 10, 2001).]
 
Raveendran Karunakaran
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i toe the line of others who have replied. Because i really feel that if the user has to be directed each time to the server to check whether the entry is correct then it would be a real waste of resources.
but check could be made using javascript for checking if the id is entered incompletely like userid without password or vice-versa. or when entered completely blank then javascript could be used along with the server side. where the errors could be caught and displayed on the screen.
this is my humble opinion.
 
Ronald Francis
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have faced all the problems mentioned before.But becuase of the performance benefits of using JavaScript for validation ,I used the following solution :
1) cleanly separate the JavaScript code into .js files eg. login.js
2) Use hidden frames, or floating frames to load them (js files)all once for the entire session of the user.
Think it over and see if you like it ..
Also, to speed trips to the server for validation ( incase you need to validate using a database , for example) , try posting data to a servlet from a hidden frame.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!