Note that there are some explanatory texts on larger screens.

plurals
  1. POJSP form values passed to a servlet
    text
    copied!<p>I have a form in JSP in the following manner : </p> <pre><code>&lt;form id="provision-field" method="post" action="${pageContext.request.contextPath}/myServlet"&gt; &lt;fieldset&gt; &lt;ol class="fields"&gt; &lt;li&gt; &lt;label for="field1"&gt;field1&lt;/label&gt; &lt;input type="text" id="field1" " value="&lt;%= field1 %&gt;" /&gt; &lt;span class="description"&gt; &lt;span class="optional"&gt;Optional&lt;/span&gt; &lt;/span&gt; &lt;/li&gt; &lt;/ol&gt; &lt;/fieldset&gt; &lt;div class="actions"&gt; &lt;button type="submit" name="Submit"&gt; Submit form &lt;/button&gt; &lt;a href="" class="close-dialog"&gt;Cancel&lt;/a&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>I have a js snippet on click of the submit button does the following</p> <pre><code>var field = document.getElementById("field1").value; $.ajax({ url: '${pageContext.request.contextPath}/myServlet' type: 'POST', data: field, dataType: "html", success: function(html) { alert("Success"); }, error: function(error){ alert("ERROR"); } }); </code></pre> <p>When I just use the form element (ie take out the js code) , I can reach my servlet but none of my form parameters are passed . when I try using the js code , the ajax request does not work . could someone point to me how this should be correctly done .</p> <p>The servlet code is :</p> <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { logger.info("Inside the post function"); logger.info(request.getParameter("data"); } </code></pre>
 

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