The most intelligent Java IDE
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JSP
 
RSS feed
 
New topic
Author

refreshing problem

vikasids sharma
Ranch Hand

Joined: Aug 01, 2003
Messages: 157

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

Thanks
Vikas Sharma
SCJP(1.4)
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Messages: 2710

Moving to the JSP Forum...
Nischal Tanna
Ranch Hand

Joined: Aug 19, 2003
Messages: 178

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

Thnx
vikasids sharma
Ranch Hand

Joined: Aug 01, 2003
Messages: 157

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

Thanks
Vikas Sharma
SCJP(1.4)
David O'Meara
Sheriff

Joined: Mar 06, 2001
Messages: 11883

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

Bad things happen when good people do nothing
[JavaRanch FAQ] [twitter] [Blog] [Book Promotions] [DbTamer]
bharat nagpal
Ranch Hand

Joined: Oct 26, 2002
Messages: 76

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
 
jQuery in Action
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » JSP
 
RSS feed
 
New topic
hibernate profiler