Note that there are some explanatory texts on larger screens.

plurals
  1. POReading input with ajax and Java servlet
    primarykey
    data
    text
    <p>i am new to java and ajax and servlets. i wrote a program that reads input from the user and prints out the dictionary meaning to the web page with the help of some tutorials.</p> <p>When i read the input from the webpage in doPost method of the servlet, it fails to read it and returns null. maybe it is trying to read the input before the submit button. How am i going to solve this? Here is the related code of my jsp file:</p> <pre><code>function ajaxFunction() { if(xmlhttp) { var inword = document.getElementById("inputWord"); xmlhttp.onreadystatechange = handleServerResponse; xmlhttp.open("GET","gettime?inputWord="+ inword.value , true ); //gettime will be the servlet name xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp.send(null); } } </code></pre> <p>...</p> <pre><code>&lt;form name="myForm"&gt; Enter the word: &lt;input type="text" name="inputWord" /&gt; &lt;br /&gt; Meaning:&lt;input type="text" name="time" /&gt; &lt;br /&gt; &lt;input type="button" onClick="javascript:ajaxFunction();" value="Click to get the Meaning on Textbox"/&gt; &lt;br /&gt; &lt;/form&gt; </code></pre> <p>And here is the part of the code that i'm trying to get the input in my servlet:</p> <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String inWord = request.getParameter("inputWord"); // word to search in the dictionary PrintWriter out = response.getWriter(); ... </code></pre> <p>everytime i try to run the project <code>request.getParameter("inputWord");</code> returns null.</p> <p>i tried some combinations of the code here <code>xmlhttp.open("GET","gettime?inputWord="+ inword.value , true );</code> like <code>xmlhttp.open("GET","gettime", true );</code> but didn't work.</p> <p>and also i call <code>doPost(request,response);</code> in my doGet method.</p> <p>any help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload