0

I am new to JQuery. I have a servlet which will fetch data from the database and the result is kept is request and the same result is retrieved in jsp file. Now i have to call the servlet using ajax jquery to load the data. I am doing as below. But it is not loading. Please help me.

$('#myForm #revert').click(function() {

        $.ajax({
            type: "GET",
            url: "./myController",
            success: function(msg) {
                <span style="color:green;font-weight:bold">Successful</span>');
            },
            error: function(ob,errStr) {
                //Todo

            }
        });

        });

Servlet code:

//Service call gets data and the result is kept in request scope as below
request.setAttribute("myresult", result);
request.getRequestDispatcher("/WEB-INF/myScreen.jsp").forward(request, response);

Thanks!

1
  • I doubt this is valid JS - have you checked in your browsers error console? Commented Aug 7, 2013 at 10:22

1 Answer 1

1

Ajax is not a normal HTTPRequest,You canot Forward or sendRedirect a Ajax request

Since it is Asynchronous,you need to write the response for Ajax request

PrintWriter out = resp.getWriter();
out.println(resultString);
return;

Please read @Balusc great answer :How to use Servlets and Ajax?

Sign up to request clarification or add additional context in comments.

5 Comments

suresh, Thanx for ur reply. How can the data is forwarded to jsp? do i need do any changes in jquery? Thanks
@user1016403 A complete example ..from HTML to Response writing is given there.If you still have a doubt,Please let me know.
it just says how display small text.But here i get list of objects from database which needs to be displayed in jsp table. Please help me...
@user1016403 send that list as a Json string to client.That is the only way I know.
@user1016403 This is the best link I can provide for you ,so far.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.