Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 每次进行ajax调用时都会加载JSP_Java_Ajax_Jsp - Fatal编程技术网

Java 每次进行ajax调用时都会加载JSP

Java 每次进行ajax调用时都会加载JSP,java,ajax,jsp,Java,Ajax,Jsp,我正在创建Hang man,其中显示的文本字段的数量等于word中要猜测的字符数。有一个单独的文本字段,用户在其中键入一个字符,然后通过单击按钮的ajax调用将该字符发送到servlet。这是我的jsp代码 <body> <% //Input streams for file read File dictionary= new File("D:\\FatimaArshad05241/Dictionary.txt");

我正在创建Hang man,其中显示的文本字段的数量等于word中要猜测的字符数。有一个单独的文本字段,用户在其中键入一个字符,然后通过单击按钮的ajax调用将该字符发送到servlet。这是我的jsp代码

<body>
        <%        //Input streams for file read
        File dictionary= new File("D:\\FatimaArshad05241/Dictionary.txt");
        FileReader fr= new FileReader(dictionary);
        LineNumberReader ln= new LineNumberReader(fr);
       RandomAccessFile raf = new RandomAccessFile(dictionary, "r");
        //counter to count number of lines
        int counter=0;
        //count number of lines
        while(ln.readLine()!=null){
        counter++;
        }
        //generate a random line number
       Random rnmber = new Random();
       int line=1+rnmber.nextInt(counter);
       String word="";
       int c=1;
       //position pointer to the top of file
       word= raf.readLine();
        raf.seek(0);
       //fetch the word
      while(raf!=null){

        if(c==line){
             //System.out.println("oh here");
             break;

        }
        else{

          word=  raf.readLine();

            }

         c++;

        }
      char[] array= new char[200];
      System.out.println("The word is");
      System.out.println(word);
      counter=0;
      for(int i=0; i<word.length();i++){
        array[i]= word.charAt(i);
        counter++;
      }
      %>
        <% for(int i=0; i<counter;i++){%>
            <input type="text" name="<%=i%>" id="<%=i%>"/>
            <%}%>
        <form>

                <br/>   
                 <br/> 
                  <br/> 
           <input type="text" name="t" id="t"/>
           <input type="button" name="a" id="a" value="enter"/>


       </form>


        <script>
            $("#a").click(
            function(e){
                var wordguessed= $("#t").val();
                $.GET("HangMan.java",{word:<%=word%>,wordguessed=wordguessed}, function(data,value){

                <%System.out.println("so u did it :p");%>

                alert(data);

            });

            }        
            );

        </script>


    </body>

我不想再次加载JSP。有什么我不知道的吗?

你确定JS被调用了吗?一个servlet的奇怪名字
HangMan.java
@ScaryWombat语句在ajax成功函数中被执行了。你能告诉我们你是怎么知道的吗。servlet的名称很奇怪,在JS中使用
%=word%
也很奇怪。检查生成的HTML是否确实调用了JS?servlet
HangMan的名称很奇怪。执行ajax成功函数中的java
@ScaryWombat语句。您可以告诉我们您是如何知道的吗。servlet的名称很奇怪,在JS中使用
%=word%
也很奇怪。请检查生成的HTML
protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        System.out.println("So the word guessed khhftuuuuuuuuuuygyhhgis");
           String word= request.getParameter("word");
           String wordguessed= request.getParameter("wordguessed");
           System.out.println("So the word guessed is"+wordguessed);

        }