1

I need to send the data of input text to my controller with other data, I don't know how to get the text from input text and send to controller, help me

<!-- Modal content-->
<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Save news</h4>
    </div>
    <div class="modal-body">

        <%
            String link = request.getParameter("link");
         %>

        <input type="text" placeholder="Please enter news heading" name="NewsName" id="a1"/>
        <input type="hidden" value="<%=link %>" name="link"/>
        <input type="hidden" value="1" name="id"/>
        <label><%=link %></label>
    </div>
    <div class="modal-footer">
        <form method="post" action="doSaveNews?NewsName1=<%=NewsName %>">
            <button type="submit" class="btn btn-default" data-dismiss="modal">Save</button>
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </form>
    </div>
</div>

error:

NewsName cannot be resolved to a variable.

Arun Sudhakaran
  • 2,167
  • 4
  • 27
  • 52

1 Answers1

0
<form method="post" action="doSaveNews?NewsName1=<%=NewsName %>">

<%=NewsName %>

you are trying to submit the url using a variable called "NewsName" it is supposed to be a Java object because it is inside the scriptlet tag.

What you need to do is.

  • Get the value of the input element in javascript.
  • Write a "onSubmit" method in javascript, serialize the form & then form your url in javascript, submit the form.

This link might help serializing and submitting a form with jQuery POST and php

Sujal Mandal
  • 975
  • 1
  • 14
  • 29