【问题标题】:Show data in webpage from database [duplicate]从数据库中显示网页中的数据[重复]
【发布时间】:2018-07-15 13:11:20
【问题描述】:

假设,我已经更新了我的数据库,我的意思是我在我的数据库中插入了一行新数据。现在,我想通过该数据编辑我的网页,我该怎么做?

假设,我的数据库“名称”、“图片”和“年龄”中有三列,现在我想在应用了 CSS 的 HTML 页面中显示这些列的最新行。我该怎么做,请告诉我 JSP 和 servlet 方面的代码。

【问题讨论】:

    标签: css html jsp servlets


    【解决方案1】:

    首先从数据库中获取 servlet 中的值,然后在网页中显示它

    你可以做两件事:

    1. 使用request.setAttribute("id",value) 在servlet的GET方法中,

      request.setAttribute("name",value) request.setAttribute("picture",value) request.setAttribute("age",value) 而在jsp中,你可以得到这些值

      request.getAttribute("name") request.getAttribute("picture") request.getAttribute("age")

    2. 型号

      model.addAttriute("name",value)

    使用 JSTL 库,然后在 jsp 中通过以下方式获取这些值:

    ${name} ${picture} ${age}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-26
      相关资源
      最近更新 更多