problem including .js using Java web server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mickey0
    New Member
    • Jan 2008
    • 142

    #1

    problem including .js using Java web server

    hello,
    I'm writing my own web server that take a query and respond with the page;
    It seems OK. FF nothing console errors.
    Problem is when I tried to include in my file html a file "javas.js": FF gets strange error as:
    Code:
    Error: missing ; before statement
    Source Code: http://localhost/javas.js
    Row: 1, Column: 5
    Source Code:
     200 Document Follows
    I tried to do javas.js empty: the same error: where can be the error?
    Code:
    <html>
    <head>
    <script language="javascript" src="javas.js"> </script> //without this all is ok
    <script>
    function myFunc () {
           for (var i=0; i < 100; i++) {
                var table = document.getElementById("intro");  
                var row = document.createElement("tr");
                var cell = document.createElement("td");
                var link = document.createElement("a");    
                link.setAttribute("href", "http://www.google.com");
                var linkText = document.createTextNode(" HI ");     
                link.appendChild(linkText);
                cell.appendChild(link);
                row.appendChild(cell);
                table.appendChild(row);        
        }
    }   
    </script>
    
     </head>
     <body onload="myFunc()">
        <table style="width: 100%" border="5" >
           <tr><td>  Rsult </td> </tr>
            <tbody id="intro"> </tbody>
        </table>
    </body>
    </html>
    However: the content in the page appear properly (only I'd like include a js. to do other thing)

    thanks
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Have you got script tags within the JavaScript file?

    Comment

    • mickey0
      New Member
      • Jan 2008
      • 142

      #3
      sorry, I don't know what you mean; script tags inside js file? like as <script> </script>; if you mean this, no i haven't it, only javascript code. Why?
      But the problem is that the server don't display properly th page whenever I have the "line" that include include that file (it doesn't work even if the file is empty)

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Yes, that's what I meant. That could possibly have been the cause of this error.

        When you have the error on row 1, column 5, what are the contents of the JS file?

        Comment

        • mickey0
          New Member
          • Jan 2008
          • 142

          #5
          sorry I forget...The page is displayed properly on local. The problem arise only when i lauch my web server and those strange errror occur....It seems that with this web server I can't include external file.....

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Which web server software are you using?

            Comment

            • mickey0
              New Member
              • Jan 2008
              • 142

              #7
              Originally posted by acoder
              Which web server software are you using?
              I using this minimal

              Repeat: it works with html without .js. Maybe any changes has to do? thanks.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                I've copied this thread to the Java forum. Hopefully you'll get help with possibly modifying the Java code.

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  What's the output with


                  [CODE=javascript] <html>
                  <head>
                  <script language="javas cript" src="javas.js"> //without this all is ok
                  <script language="javas cript">
                  function myFunc () {
                  for (var i=0; i < 100; i++) {
                  var table = document.getEle mentById("intro ");
                  var row = document.create Element("tr");
                  var cell = document.create Element("td");
                  var link = document.create Element("a");
                  link.setAttribu te("href", "http://www.google.com" );
                  var linkText = document.create TextNode(" HI ");
                  link.appendChil d(linkText);
                  cell.appendChil d(link);
                  row.appendChild (cell);
                  table.appendChi ld(row);
                  }
                  }
                  </script>

                  </head>
                  <body onload="myFunc( )">
                  <table style="width: 100%" border="5" >
                  <tr> Rsult
                  <tbody id="intro">
                  </table>
                  </body>
                  </html>[/CODE]

                  Comment

                  • mickey0
                    New Member
                    • Jan 2008
                    • 142

                    #10
                    Nothing change with your hint; I think it a server problem (not of my page)
                    when that server start the javas.js file isn't find; In fact I tried to put the javascript code into .js and (always with the server on), the error on console is that it can't find myFunc() definition..... (repeat to note: if I delete line that include javas.js and put every javascript code into html, it works).Do anyone know how start that server?
                    I launch it as: java -jar server.jar mypage.html
                    At the moment my html is changed to keep it transitional:
                    Code:
                    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                    <html xmlns="http://www.w3.org/1999/xhtml" >
                    
                    <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                    <title> home </title>
                    <script type="text/javascript" src="javas.js"></script>
                    
                    <script type="text/javascript">
                    /* <![CDATA[ */
                    function myFunc () {
                           for (var i=0;i<100;i++) {
                                var table = document.getElementById("intro");  
                                var row = document.createElement("tr");
                                var cell = document.createElement("td");
                                var link = document.createElement("a");    
                                link.setAttribute("href", "http://www.google.com");
                                var linkText = document.createTextNode(" HII ");     
                                link.appendChild(linkText);
                                cell.appendChild(link);
                                row.appendChild(cell);
                                table.appendChild(row);        
                        }
                    }   
                    /* ]]> */
                    </script>
                     </head>
                     
                    <body onload="myFunc()">
                        <table style="width: 100%" border="5" >
                            <thead><tr><td> Home Page </td> </tr></thead>
                            <tbody id="intro"><tr><td> </td></tr> </tbody>
                        </table>
                    </body>
                    </html>

                    Comment

                    • mickey0
                      New Member
                      • Jan 2008
                      • 142

                      #11
                      Does anyone know how run and use this server?

                      Comment

                      Working...