javascript - Modifying server side text file -


currently working on static html website. using following javascript code read server side text file:

<!doctype html> <html> <head> <script>     function loadxmldoc() {         var xmlhttp;         if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari             xmlhttp = new xmlhttprequest();         }         else {// code ie6, ie5             xmlhttp = new activexobject("microsoft.xmlhttp");         }         xmlhttp.onreadystatechange = function () {             if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {                 document.getelementbyid("mydiv").innerhtml = xmlhttp.responsetext;             }         }         xmlhttp.open("get", "results.txt", true);         xmlhttp.send();     } </script> </head> <body>  <div id="mydiv"><h2>content</h2></div> <button type="button" onclick="loadxmldoc()">change content</button>  </body> </html>  

here on click event data displayed.but want change content of text file on click event.i want increment number 1 resides in file content.

please me this...thank in advance.!!

edit:

i using windows hosting.

you may this

this index page. have done in jsp.

index.jsp

<!doctype html> <html> <head> <script>     function loadxmldoc() {         var xmlhttp;         if (window.xmlhttprequest) { // code ie7+, firefox, chrome, opera, safari             xmlhttp = new xmlhttprequest();         }         else { // code ie6, ie5             xmlhttp = new activexobject("microsoft.xmlhttp");         }         xmlhttp.onreadystatechange = function () {             if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {                 document.getelementbyid("mydiv").innerhtml = xmlhttp.responsetext;             }         }         xmlhttp.open("get", "newjsp.jsp", true);         xmlhttp.send();     } </script> </head> <body>     <div id="mydiv">         <h2>content</h2>     </div>     <button type="button" onclick="loadxmldoc()">change content</button> </body> </html>  

then server side coding

newjsp.jsp

<%@page contenttype="text/html" pageencoding="utf-8" import="java.io.*"%> <%     try {          bufferedreader in = new bufferedreader(new filereader("c:/users/sar/documents/netbeansprojects/webapplication1/web/results.txt"));         // change path txt file         string line;         int = 0;         if((line = in.readline()) != null)             = integer.parseint(line)+1;         else             = 1;            printwriter pw = new printwriter(new fileoutputstream("c:/users/sar/documents/netbeansprojects/webapplication1/web/results.txt"));         // change path txt file         pw.println(a);         pw.close();         out.println(a);     }     catch(exception e)     {         e.printstacktrace();     } %> 

you have create results.txt file @ location specified.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -