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

Displaying a Confermation Message

abinash das
Ranch Hand

Joined: Apr 26, 2008
Posts: 52

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

Joined: Aug 03, 2008
Posts: 9305
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Anurag Blore
Ranch Hand

Joined: Jan 15, 2003
Posts: 74
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.

Thanks,
Anurag
SCJP 1.2 & 1.5, PMP
abinash das
Ranch Hand

Joined: Apr 26, 2008
Posts: 52
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

Joined: Dec 29, 2008
Posts: 162
where have you called the alert box? I mean in the form's action element or SUBMIT button's onSubmit element?


The greater danger for most of us is not that our aim is too high and we miss it, but that it is too low and we reach it
abinash das
Ranch Hand

Joined: Apr 26, 2008
Posts: 52
i am calling at bodyOnload
Sujai Kaarthik
Ranch Hand

Joined: Dec 29, 2008
Posts: 162
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

Joined: Apr 26, 2008
Posts: 52
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

Joined: Dec 29, 2008
Posts: 162
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

Joined: Apr 26, 2008
Posts: 52
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

Joined: Oct 08, 2006
Posts: 2458
Use JSTL to control the presentation logic conditionally.

For example

or so.
 
jQuery in Action, 2nd edition
 
subject: Displaying a Confermation Message