aspose file tools*
The moose likes JSP and the fly likes Update Database with the better way Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Update Database with the better way" Watch "Update Database with the better way" New topic
Author

Update Database with the better way

naro pad
Ranch Hand

Joined: May 07, 2008
Posts: 58

I have a form where I read data from database and fill some text fields. Now the user can make changes on them and save them.

Now what mechanism I have think about to update the tables is to save them temporary into objects and when the form is submit to check the object with the right getParameter to see if they differ and update the table.

Is there any better way. For example using AJAX or anything else?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30973
    
159

Panayiotis,
What you described is the basic outline. You would need to do the compare regardless of whether you use AJAX.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Xinsheng Chen
Greenhorn

Joined: May 28, 2008
Posts: 7
You can check whether the content is changed or not on the client side using JavaScipt. On the cursor moving away or the "Submit" button being pressed, you use JavaScript code to check whether the content is changed or not. You set a "changed" hidden input value to true or false accordingly. On your server side, you first get the value of "changed" and check it -- If the content is not changed, you avoid a trip to the the database.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61662
    
  67

Originally posted by Xinsheng Chen:
You can check whether the content is changed or not on the client side using JavaScipt.

Sorry, but that is not a very good idea. You can never trust what the client sends (it can easily be spoofed) and you cannot control whether the user might turn JavaScript on or not.

All important business logic must take place on the server.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
naro pad
Ranch Hand

Joined: May 07, 2008
Posts: 58

Ok thanks a lot for the replies...
I will see what I will do
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
All important business logic must take place on the server.

I Agree. Doing this type of validation on the client side is always unsafe. Instead,

1) you can store them in to a bean/form.
2) Write a logic to connect to the database and update the values in a DAO.
3) Use/Call this DAO from the corresponding servlet.
[ May 28, 2008: Message edited by: Prasad Tamirisa ]

Regards,
Durga Prasad
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Update Database with the better way