Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display Message when I insert or update record

 
Dev Anand
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a form in Jsp. When I click 'submit', it goes to one Servlet page to do insert or update operations.
Now, I want to display a message when I insert or update record. When I press the Ok button of the message then, the application should be redirected to the home page.

//---------------------code Start-----------------


//-------------------------EndCode----------

[Edit:added code tags]
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dev,
Yes your code does what you need. What is your query ?
 
Dev Anand
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Balu,
When I execute that code, I'm not getting the Javascript message. The application is directed to the given page.

With Regards
Dev Anand. P
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you are trying to do is display an alert message and dispatch the request to a page at the same time. This is not possible in the way you want. You'll have to set a request attribute of the success/error message and then the page to which you redirect the request (AdminHome.jsp/AddRegion.jsp) should check if there is a success of failure message and display an alert message or simple message on top of the page. So basically you'll have to show the message on the JSP page. Right now you might get an alert message if update of a record fails (I used might as there are not <html> or <head> tag in the code that you send to the client so browser might not be able to parse it). The alert on successful update of record is commented and if you uncomment it, then you might face an IllegalStateException on the request dispatcher step...
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

No you cannot. Javascript executes at client side and servlet executes at server end. Why cant throw a confirmation page instead of javascript alert.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic