title: How to redirect/forward request to another jsp page in servlet called by $.ajax() function
body: <p>I am using $.ajax() function to call servlet in my application and i am forwarding request to anothor jsp page and setting request attribute.....I just want to know is it good approach to forward request and setting request parameter in ajax based servelt?
  Here is my sample code.....</p>
  
  <pre><code>          var id= $("#id").val();
  
            $("#add-btn").click(function(e) {                                                                                                 
                  e.preventDefault();         
                  var dataString ='action=insert'+'&amp;id='+id
                  console.log(dataString);
                  $.ajax({
                      type: "POST",
                      url: "RecordHandler",
                      data: dataString,
                      success: function(data){  
                          console.log('Add');
                          $('body').html(data);
                          $('body').prepend('&lt;div style="width:100%;text-align:center;"&gt;&lt;h3 style="color:green" &gt;Record Added Succesfully&lt;/h3&gt;&lt;/div&gt;')
                      }
                  });  
  
              });
  </code></pre>
  
  <p>and here is my servlet code......</p>
  
  <pre><code>  private static String UserRecord = "/list.jsp";
  
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
  
      String redirect = "";
      String action = request.getParameter("action");
      if (action.equalsIgnoreCase("insert")) {
        String id= request.getParameter("id");
        int uid = Integer.parseInt(id);
        RecordBean record = new RecordBean();
        record.setId(uid);
        dao.addRecord(record);
        redirect = UserRecord;
        request.setAttribute("records", dao.getAllRecords()); //Is it good approach to set request attribute in ajax based servlet?
        System.out.println("Record Added Successfully");
  
        RequestDispatcher view = request.getRequestDispatcher(redirect);//Is it good approach to redirect request in ajax based servlet?
        view.forward(request, response);
   }
  </code></pre>
  
  <p>How to do it using ajax without refreshing page......
  even i use window.location.herf="list.jsp" in ajax success method it is refreshing page</p>