【问题标题】:How can I add table to ajax response如何将表格添加到 ajax 响应
【发布时间】:2016-10-26 09:14:12
【问题描述】:

这是我的代码。我尝试了很多。但找不到任何运气。我希望 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();
                }
            }

谢谢。

【问题讨论】:

标签: javascript java ajax


【解决方案1】:

您只需将对象“emp”转发到您的视图页面(即 jsp 页面)并可以将详细信息打印为表格形式

【讨论】:

  • 怎么样?不要得到你。
  • json.addData("emp", emp);
  • json.addData("emp", emp);我刚刚将“carList”转发到我的“jsp页面”
【解决方案2】:
  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 页面。我刚刚将“carList”转发到我的“jsp 页面”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-26
    相关资源
    最近更新 更多