hanu
hanu

Reputation: 61

Jsp page not displaying the contents of modified xml file until i manually refresh the folder in which the xml is located

I am developing a web project in which i call one Java class which updates the XML file and then i redirect the request to a JSP which displays the contents of that updated XML file. But the updated XML values are not being displayed until i manually refresh the folder which contains that XML file.

Template of my code is..

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    String instanceName=request.getParameter("instanceName");
    int no_of_days=Integer.parseInt(request.getParameter("days"));

               CopyOfUpdateXmlLicenses obj2=new CopyOfUpdateXmlLicenses(instanceName,     new_free_lic);
    obj2.updateXML_Licesnes();
               long time=new Date().getTime();
    response.sendRedirect("Licenses.jsp?ms="+time); 
}

Upvotes: 0

Views: 535

Answers (3)

hanu
hanu

Reputation: 61

Thank you all for spending your time on my question. I found the root cause for the above mentioned problem.

There's no problem with the code, rather with the Eclipse IDE. The IDE takes some time to refresh the contents of the workspace. So in the mean time, if our program tries to read the contents of a file which is in the workspace, the changes may not get reflected immediately. So try to check the web application by deploying it onto tomcat.

If you want to execute it in the Eclipse IDE, then go to window-> preferences->general->workspace and select the option "refresh automatically."

Upvotes: 1

BalusC
BalusC

Reputation: 1108692

You're making a major design mistake. The webapp should not write to the deploy folder during runtime and well due to the following main reasons:

  • All changes get lost whenever you redeploy the WAR or restart the server. Simply because those changes are not contained in the (original) WAR.

  • Some servers does not expand the WAR on disk, but in memory instead. The getRealPath() would then return null, making you unable to write files to it.

Your concrete problem is by the way caused because you're deploying and running the webapp by an IDE. The IDE does not immediately spot any changes in the project's folder structure which are done externally. But you should realize that the IDE is not a server and does not run in production environment. The IDE is just a development tool.

You need to write the file to a fixed path outside the deploy folder instead.

Upvotes: 4

segFault
segFault

Reputation: 1228

I would make a servlet called Licenses.java and then redirect the page to licenses with the new time or just have the servlet generate the new time on load to compare it to the old time that it has. Then have the servlet do the logic and then forward the page to licenses.jsp.

Upvotes: 1

Related Questions