Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

refreshing problem

 
vikasids sharma
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
i m using JSP for front end .
A controller servlet for controlling the flow of application and beans for inserting a record in database.
I give a message to user after sucessfull insertion of record in database(using alert message of javascript).
Now record is inserted once but message is displayed every time i refresh page which is irritating to user.
Can anybody tell me how to stop displaying message when user presses refresh action of browser.
Thanks in advance
vikas
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the JSP Forum...
 
Nischal Tanna
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i guess this is a common problem with JSPs .but i guess ur data is incomplete for solving.i guess if u provide a code snippet then it can help.anyways or else take a session attribute by using.
String ses=session.getValue("action")
the very first time the value of ses will be null.so take a if loop ..
if((ses==null)||(ses.equals(""))
{
//give the database calling code here..i mean ur application logic
}
else
{
out.println("you have already inserted ur record");
}
i hope this gives u a hint..
regards,
Nischal
 
vikasids sharma
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks but can i have some other alternative to it rather than using Session Object.
Originally posted by Nischal Tanna:
Hi i guess this is a common problem with JSPs .but i guess ur data is incomplete for solving.i guess if u provide a code snippet then it can help.anyways or else take a session attribute by using.
String ses=session.getValue("action")
the very first time the value of ses will be null.so take a if loop ..
if((ses==null)||(ses.equals(""))
{
//give the database calling code here..i mean ur application logic
}
else
{
out.println("you have already inserted ur record");
}
i hope this gives u a hint..
regards,
Nischal
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are some patterns solving this related to the MVC architecture, but the easiest way is to execute a response.sendReirect() to a confirmation page after the data has been posted.
This should be done using a Controlling Servlet and managing the Views in the JSPs and works the same way as the example here
Dave
 
bharat nagpal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you insert the value in the database, simply set one boolean variable to true. then you can make that boolean value available in JSP page, and if you don't want to use session object you can use request object for this. while callling Javascript method, you can pass this value to that method from within JSP page.(in <%%>
hth
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic