How to use servlets and Jquerry+bootstrap?

I have button:

<button id="saveFeed" type="button" class="btn btn-primary">Save changes</button>

in form:

<div class="modal fade" id="myModal">
                                    <div class="modal-dialog">
                                        <div class="modal-content">

                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal"
                                                    aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                                <h1 class="modal-title">Edit feed name:</h1>
                                            </div>

                                            <div class="modal-body">
                                                <input type="hidden" readonly="readonly" name="id"
                                                    value="<c:out value="${feed.id}" />" />

                                                <p>Enter feed name:</p>

                                                <input id="feedName" type="text" name="name"
                                                    value="<c:out value="${feed.name}" />" />
                                                <!--                            <input id="feedName" type="text" name="feed name"> -->
                                            </div>

                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default"
                                                    data-dismiss="modal">Close</button>


                                                <button id="saveFeed" type="button" name="feedSub"
                                                    class="btn btn-primary">Save changes</button>
                                            </div>

                                        </div>
                                        <!-- /.modal-content -->
                                    </div>
                                    <!-- /.modal-dialog -->
                                </div>
                                <!-- /.modal -->

script for jQuery:

<script>
    $('#myModal').on('shown.bs.modal', function() {
        $('#myInput').focus();
    });

    $(document).ready(function() {

        $('#saveFeed').click(function() {
            var feedName = $('#feedName').val();
            var feedId = $('#id').val();
            $('#myModal').modal('hide');
            $.post('FeedController', {
                feedName : feedName,
                feedId : feedId
            }).done(function(data) {

            });
        });

    });
</script>

servlet:

protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
    else if (req.getParameter("feedSub") != null) {
                String link = null;
                String name = req.getParameter("name");
                Integer id = Integer.parseInt(req.getParameter("id"));

                feed = new Feed(id, link, name);

                feedDAO.update(feed);
            }

            resp.sendRedirect("FeedController?action=feedList");
}

I need to rename feed using jQuerry but i am completly new to it. How to redirect to servlets handler button after save changes button was pressed using jQuery script?


Source: jquery

Leave a Reply