• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying a Confermation Message

 
abinash das
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In My Application i have a requirement of submitting a bulk data say(a Person's Detail)to database.
Once a perticular record is submitted to dB, I want a message to be displayed that the person is Successfully Added To DB.
And User can Add one more Person Info.

What i deed is after submitting the data if there's no error came i assigned the result as Success.
And Stored in the request object with key say "key".

In the JSP page i am having a hidden parameter whose value is assigned by the following

<CODE>
<input type="text" name="status" value=<%=request.getParameter("key") %>

</Code>
In the above key is the key that i am using to Store the status of data insertion.

In the javaScript i am checking the status value and if it's Success then givs a alert like "Data Submitted Successfully" .


But in this approach,

the problem is even though the user try to refresh the page he is getting a status like "Data Submitted Successfully".


I want to avoid it,
Can any body suggest me what should i do to get my desired requirement ?

Thanks In Advance



 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all this doesn't look like a hidden field to me



This is a text field. I suppose you meant this



Also why are you making it complicated by using javascript in this. If you want to show a pop up box to the user then its ok. The second thing is that if you are setting the key in the servlet which stores the data in the database, then you must have set an attribute instead of parameter. So your code would look like



or even better



And this is a problem of double posting I think. Not only will the user be displayed the message, the data will also be persisted more than once. So you'll have to make sure that this is avoided. For that you must use a unique ID sort of a thing which is stored in the session as well as sent to the browser to identify that the same thing has been posted more than once...
 
Anurag Blore
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can add an id as mentioned below to your input type text box.



Then at the end of jsp try this in java script


This will help you to clear the field after the page load and while referesh there will be no issues.
 
abinash das
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried with clearing the value but it's not getting cleared,

Because when ever i refresh also the status comes as a alert.

Some more customization is required ,can anybody suggest any other way to achieve the same

 
Sujai Kaarthik
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where have you called the alert box? I mean in the form's action element or SUBMIT button's onSubmit element?
 
abinash das
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am calling at bodyOnload
 
Sujai Kaarthik
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then it will pop-up everytime you load that page. Try to add alert box when you submit the form.

between, once you submit the form, where the page redirects? to the same page or other page?
 
abinash das
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In My application what i deed is from a jsp page i am submitting the dat to a Servlet,
From the Servlet i am invoking a DAO to insert into DB.
After i am done i am getting a response back as "Success or Failure".

Then I am using response.redirect to a servlet which constructs the parameters for the .jsp


So, Can you suggest me where to use the alert.?
 
Sujai Kaarthik
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I am using response.redirect to a servlet which constructs the parameters for the .jsp

what is the intended purpose of this action?

after inserting in the DB, where do your page redirects? to the same page or anyother page?

I guess that alert box is your only problem. right?
 
abinash das
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The intention is to show some Conformation message to User that the given data is Successfully inserted
into Database.And i am redirecting the request to a Servlet which takes certain values from the DB, and then
dispatches the request to the .jsp page.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use JSTL to control the presentation logic conditionally.

For example

or so.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic