将自定义对象从servlet传递到ajax并显示在jsp页面中

时间:2014-12-10 10:34:16

标签: java jquery ajax jsp servlets

是否有任何方法将custom对象从servlet传递到ajax并在jsp页面中显示? 当从jsp页面接受库存id时,它会传递给servlet并根据id获取库存对象。之后,我想将库存对象传递回ajax并在jsp页面中显示

1 个答案:

答案 0 :(得分:0)

这可能是你的答案,因为你没有深入描述你的问题。

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class Test extends HttpServlet {

  // Method to handle GET method request.
  public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
  {
      //declaring custom object
      Person person = new Person("FirstName","LastName");

      PrintWriter out = response.getWriter();
      out.print(person);
  }
  // Method to handle POST method request.
  public void doPost(HttpServletRequest request,
                     HttpServletResponse response)
      throws ServletException, IOException {
     doGet(request, response);
  }
}