如何将表添加到ajax响应中

时间:2016-10-26 09:14:13

标签: javascript java ajax

这是我的代码。我尝试了很多。但无法找到任何运气。我希望ajax响应应该以表格形式出现。

 if (URI.endsWith("updateEmpById.action")) {
                Employee emp;
                try {
                    emp = new EmployeeDaoImpl().findEmployee(Integer
                            .parseInt(request.getParameter("val")));

                    out.print("<div>");
                    out.print("<form action='UpdateEmployee.action'><p> ID:<input type='number' name='id' value='"
                            + emp.getId() + "'  readonly></p>");
                    out.print("<p> NAME:<input type='text' name='name' value='"
                            + emp.getName() + "'></p>");
                    out.print("<p> DESIGNATION:<input type='text' name='desig' value='"
                            + emp.getDesignation() + "'></p>");
                    out.print("<p> SALARY:<input type='text' name='salary' value='"
                            + emp.getSalary() + "'></p>");
                    out.print("<p><input type='button' value='Update' class = 'button'></p></form>");
                    out.print("</div>");
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

感谢。

2 个答案:

答案 0 :(得分:0)

你只需转发对象&#34; emp&#34;到您的视图页面(即jsp页面)并可以以表格形式打印详细信息

答案 1 :(得分:0)

  ArrayList<ArrayList<String>> carList = new ArrayList<ArrayList<String>>();
  List<CarInfo> carById = carInfoService.getCarDetail(carId);

        if (carById != null) {
            for (CarInfo carId : carById) {
                ArrayList<String> carDetail = new ArrayList<String>();
                carDetail.add(carId.getFirstName());
                carDetail.add(carId.getLastName());
                carList.add(carDetail);
            }
            json.putStatus(1);
            json.addData("carList", carList);
        }

这是我的java页面。我刚刚转发了&#34; carList&#34;到我的&#34; jsp页面&#34;