【问题标题】:Pass Custom object from servlet to ajax and display in jsp page将自定义对象从 servlet 传递给 ajax 并在 jsp 页面中显示
【发布时间】:2014-12-10 10:34:15
【问题描述】:

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

【问题讨论】:

  • 您能否详细说明您的问题?向我们展示一些代码,一些正在工作的东西,然后准确地告诉我们您还想做什么。如果您可以阅读有关如何在 SO 上提问的常见问题解答,那就太好了
  • 你如何对servlet进行ajax调用?你能提供你的代码吗?

标签: java jquery ajax jsp servlets


【解决方案1】:

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

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);
  }
}

【讨论】:

    猜你喜欢
    • 2012-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多