• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP page is not getting refreshed after successful csv file downloaded.

 
sreeni nivas
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

Can you please help me to resolve the below issues....

JSP page is not getting refreshed after successful csv file downloaded.

Issue 1: my ultimate aim to refresh the page is to clear the error message appearing on my page(current). The error message comes when user enter wrong information.
And after user has corrected that wrong information and clicking on download button, the page is not getting refreshed and error message is not going away after suceesful csv download (open/save/cancel) .


Issue2: I need to display the info message also after clearing the above error message and successful csv file download


Below is the api code for writing the data to csv and attachment,,,
public void close(String filename) throws Exception{
// TODO Auto-generated method stub
pw.close();
fileStream.close();


facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
response = (HttpServletResponse)externalContext.getResponse();
//End
response.setContentType("text/csv");
response.setHeader("Cache-Control","private");
response.setHeader("Content-Disposition", "attachment; filename=" + filename + ".csv");
stream = response.getOutputStream();

FileInputStream fis = new FileInputStream(file);
byte[] filebyte = new byte[100];
int c ;
int i=0;
c = fis.read();
while(c != -1)
{
filebyte[i] = (byte)c;
c = fis.read();
if(c == -1)
{
log.debug("Write o to i");
getStream().write(filebyte, 0, i);
}
else
{
i++;
if(i== 99)
{
//log.debug("Write filebyte");
getStream().write(filebyte);
i=0;
}
}
}
getFacesContext().responseComplete();
log.debug("CVSDataExporter#close() - Begin");
getStream().flush();
getStream().close();
fis.close();
delete();
log.debug("CVSDataExporter#close() - End");
}

Thanks,
Srini
 
Yogesh Lonkar
Ranch Hand
Posts: 94
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i find some non appropriate solution for this problem
what i did was in FORM after user clicks on submit button i added 1 more attribute in it
<s:submit ----your attributes------- onmouseup="refresh(2000) "/>
and in head tag of JSP page i added this
<script type="text/javascript">
function refresh (timeoutPeriod){
refresh = setTimeout(function(){window.location.reload(true);},timeoutPeriod);
}
</script>
it reloads the page in 2 seconds after submiting of form but if download POP did not appear before that that download get's canceled

if your download size is large you can adjust time as per your needs it's not perfect solution for this problem but rather a Duck Tape method
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!