• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display a confirmation message after checking values in the servlet?

 
Diego Nobre
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good afternoon people! When I click the Change button, I check to see if the data in the database remains the same. How do I return a confirmation window if the results are not the same?

Example: I select the material I want to change, fill in the inputs, but before clicking Change, I leave the table for some reason, and another user on another computer changes this same material. When I go back and click Change, does the data check, how do I show a message stating that the data has changed and asking if I still want to change it?
 
Henry Wong
author
Marshal
Pie
Posts: 22102
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well, servlet *and* database are server side technologies. And terms like "clicking button" and "displaying message" refers to the client side. So, what client side technology are you using? Applets? JavaScript? Flash? ... This may even help us move this topic to the correct forum.

And welcome to the ranch.

Henry
 
Diego Nobre
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Well, servlet *and* database are server side technologies. And terms like "clicking button" and "displaying message" refers to the client side. So, what client side technology are you using? Applets? JavaScript? Flash? ... This may even help us move this topic to the correct forum.

And welcome to the ranch.

Henry



I am using jsp and servlets ...

Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That doesn't really answer Henry's question. Are you using JavaScript to instrument the button in question? Or is the button causing a form to be submitted to a servlet? Or something else? We need more details than you have provided.

Generally, information (including messages) are conveyed from a servlet to a JSP by adding the data to scoped variables (aka "attributes") and forwarding to the JSP. But whether that's the appropriate course of action in this case is not yet clear.
 
Stefan Evans
Bartender
Posts: 1807
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The server side does not really change much.
It needs to detect the database concurrency issue, and inform the JSP appropriately.
I presume you have handled that side of things.

Well there are two basic options on the client side:
Option #1: Click button - send HTTP Post request via submitting a form.
- sends request, replaces current page with response.  You would need to repopulate the page as it was when submitted, and add an "error" note to the page.

Option #2: Click button - send AJAX request via javascript
- sends request, gets response into javascript variable via a callback.  You can then have javascript code execute based on the result.  Your result could be a JSON object which could either return "success" or an "error message" and then you write code to handle those cases appropriately.   However the page remains as it was when you clicked the button as the response went to javascript rather than replace the current page. 

Either works.
Using AJAX and making "single page applications" is the current trend as I understand it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic