Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting duplicate records when the page refreshes.  RSS feed

 
Soumya Madhu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am getting duplicate records while refeshing page. I am doing a JSP/Struts 1.0 web application. Plese see the code in my Action class:

if(action.equals("Submit")){

insertReports(xml);

//xml is of String type which is a xml file

//The table to which this xml is saving ,have primarykey as its Id. Each time when it is inserted, it will take the value as maxximun value of id+1.

return mapping.findForward("AddNewReport");
}

My problem is everytime I refresh the page, the above action get executed and insert a new record this same xml(its id is different). Please suggest a solution for this problem.

Thanks
Soumya
 
ujjwal soni
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Write this on top of your jsp code

Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetValidUntilExpires(false);

Cheers!!!

Ujjwal B Soni

[baroda, gujarat, india]
[919998971048]
 
Soumya Madhu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ujjwal soni:
Hi,

Write this on top of your jsp code

Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetValidUntilExpires(false);

Cheers!!!

Ujjwal B Soni

[baroda, gujarat, india]
[919998971048]


Hi,
I have given
Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetValidUntilExpires(false);

in top of my jsp. But got errors.

package DateTime does not exist.
package Response does not exist
cannot resolve symbol:
symbol : variable HttpCacheability
etc...

any thing we need to import in jsp page? am using tomcat 4.1 and java 1.4.
 
Bosun Bello
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a common problem. Search for the PRG pattern.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66143
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article describes proper web application patterns including PRG.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!