Hi...

I am creating an HTML Table in my JSP page taking values from text file. Now the problem comes when I read the file again to update the Table content. In this case I have to refresh my whole page to see updated Table. :icon_cry:

How can I refresh only the Table part of page without refreshing the whole page ? :?:

Would appreciate suggestions. :idea:

Thanks

Why don't you go for AJAX for reading txt file every time with out refreshing your page.
Google for AJAX Tutorials...

Why don't you go for AJAX for reading txt file every time with out refreshing your page.
Google for AJAX Tutorials...

Have come up with this code. Now the problem is howto generate the html table values with Ajax ? Can somebody suggest howto incorporate file reading dynamically and html table generation. There are few things I want this program to do:-

To read multiple fields from a file. So howto pass multiple parameters and then read them while putting inside html table

This is the JSP index page

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>

        <script type="text/javascript">
                 var xmlhttp

                 function loadContent(str){
                     xmlhttp=GetXmlHttpObject();

                     if(xmlhttp==null){
                         alert("Your Browser does not support Ajax HTTP");
                         return;
                     }
                     var url ="loadJSP.jsp";
                     url=url+"?q="+str;
                     //url=url+"q="+str
                     xmlhttp.onreadystatechange=getOutput;
                     xmlhttp.open("GET", url,true);
                     xmlhttp.send(null);
                 }
                 function getOutput(){
                     if(xmlhttp.readyStatechange=4){
                         document.getElementById("prtCnt").innerHTML=xmlhttp.responseText;
                         var string1 = document.getElementById("prtCnt").innerHTML=xmlhttp.responseText;
                     }
                 }
                 function GetXmlHttpObject(){
                     if(window.XMLHttpRequest){
                         return new XMLHttpRequest();
                     }
                     if(window.ActiveXObject){
                         return new ActiveXObject("Microsoft.XMLHTTP");
                     }
                     return null;
                 }
        </script>
        <script>
            function wow(){
                var mystr = document.getElementById("prtCnt").innerHTML=xmlhttp.responseText
                return  document.write(mystr);
            }
        </script>
    </head>
    <body>
        <a href="javascript:loadContent('parameterValue')">Load Ajax Content</a>
        <table border ="3"><div>

         <tr><td id="prtCnt"></td></tr>
      </div>
        </table>
    </body>
</html>

This is the other JSP program

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%
  String q = request.getParameter("q");

  //String str = "Loading JSP String from Ajax: Loading......";
  String[] str = {"one","two","three"};
  java.util.Date dt = new java.util.Date();
  for(int i=0; i<str.length; i++){
  out.println(str[i]);
  }
  out.println(dt);

Please suggest howto enhance this basic program

Thanks

Web_Sailor,

we couldn't reach your point exactly..Please come up with clear information.

As per my understanding:
And why not you design your table in loadJSP.jsp . and assign response to a div tag like :

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%
  String q = request.getParameter("q");

  //String str = "Loading JSP String from Ajax: Loading......";
  String[] str = {"one","two","three"};
  java.util.Date dt = new java.util.Date();
  for(int i=0; i<str.length; i++){
  out.println(str[i]);
 [B] // Design you table here and assign strings here[/B]
  }
document.getElementById("printTable").innerHTML=xmlhttp.responseText
<body>
        <a href="javascript:loadContent('parameterValue')">Load Ajax Content</a>
        <table border ="3">

         <tr><td><div id="printTable"></div></td></tr>
      
        </table>
    </body>

Web_Sailor,

we couldn't reach your point exactly..Please come up with clear information.

As per my understanding:
And why not you design your table in loadJSP.jsp . and assign response to a div tag like :

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%
  String q = request.getParameter("q");

  //String str = "Loading JSP String from Ajax: Loading......";
  String[] str = {"one","two","three"};
  java.util.Date dt = new java.util.Date();
  for(int i=0; i<str.length; i++){
  out.println(str[i]);
 [B] // Design you table here and assign strings here[/B]
  }
document.getElementById("printTable").innerHTML=xmlhttp.responseText
<body>
        <a href="javascript:loadContent('parameterValue')">Load Ajax Content</a>
        <table border ="3">

         <tr><td><div id="printTable"></div></td></tr>
      
        </table>
    </body>

out.println(str);
// Design you table here and assign strings here
}

Thats the problem. I am able to construct a table but with only 1 cell. Howto construct the table here so that it is dynamically constructed as usually happens ?

like this:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%
  String q = request.getParameter("q");

  //String str = "Loading JSP String from Ajax: Loading......";
  String[] str = {"one","two","three"};
  java.util.Date dt = new java.util.Date();
  for(int i=0; i<str.length; i++){
  out.println(str[i]);
  // Design you table here and assign strings here
out.println("<table><tr><td>......");
  }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.