1

I am requesting a servlet to get a String value , for that I am doing like this.

function histryTraceFun(){
    $.get('SendNodeHistoryTracing?node='+temp,function(response){
        alert("in response "+response); // Here I am not getting response
        });
} 

in servlet doGet() method I have,

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    response.setContentType("text/html");
    String node=request.getParameter("node");


}

The controll will come to servlet but not returning to JSP , in callback function alert the value of variable response is not comming. And actually I didnot understand how response.setContentType() work. can any one help me in this please. Thank you.

Raghu
  • 1,324
  • 7
  • 24
  • 47

1 Answers1

1

Try this to send control back to your page :

RequestDispatcher dispatcher = request.getRequestDispatcher("/yourPage.html");
dispatcher.forward(request, response);

You can also add data in response :

response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("your_response");

RequestDispatcher dispatcher = request.getRequestDispatcher("/yourPage.html");
dispatcher.forward(request, response);

Still problem then post me.

Look Here, more understandable & explained code by balusc.

Community
  • 1
  • 1
user3145373 ツ
  • 7,858
  • 6
  • 43
  • 62