如何使用数据库中的结果填充隐藏的HTML表?

时间:2014-05-03 09:33:06

标签: java html jsp servlets

我有一个名为create-account.jsp的JSP,它收集客户的详细信息并将数据发送到Servlet。 Servlet将客户的数据插入数据库,查询数据库添加将结果设置为请求范围属性,并将调度发送到create-account.jsp(相同的jsp)。现在插入的细节必须出现在jsp中隐藏的html表中。我该怎么做?任何人都可以帮忙吗?

创建-account.jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Create New Account</title>
    <style>
        a {
            text-decoration: none;
        }

        body {
            border-color: azure;
        }

    </style>
</head>
<body>
<p align="right">Hi, ${sessionScope.user.userName} <a
        href="${pageContext.servletContext.contextPath}/logOut.do">logout</a></p>


<h2 align="center">Create New Account</h2>

<form action="${pageContext.request.contextPath}/create.do" method="post">
    <table border="1" align="center">
        <tr>
            <td>Name:</td>
            <td><input type="text" name="name"></td>
        </tr>
        <tr>
            <td>DOB:(yyyy-mm-dd)</td>
            <td><input type="text" name="dob"></td>
        </tr>
        <tr>
            <td>Balance:</td>
            <td><input type="text" name="balance"></td>
        </tr>
        <tr>
            <td align="center" colspan="2">
                <input type="submit" value="Create" name="create">
            </td>
        </tr>
    </table>
</form>
<p align="center" style="display: none">${requestScope.result} has been successfully inserted into the table</p>
<table id="hiddenTable" style="display: none" border="1">
    <tr>
        <td>

        </td>
    </tr>
</table>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

使用

style="visibility: hidden;"

style="display:none;"

隐藏表格。

了解更多信息,请查看以下链接


如何在表格中显示结果?

示例代码:

的Servlet

public class Model{
     private String name;
     private String dob;
     private double balance;
     // getter and setter   
}

...

List<Model> list = new ArrayList<Model>();
//add the data in list

request.setAttribute("list",list);

JSP:

<c:if test="${not empty list}">
  <c:forEach var="ob" items="${list}">
     <tr>
       <td><c:out value="${ob.name}"/></td>
       <td><c:out value="${ob.dob}"/></td>
       <td><c:out value="${ob.balance}"/></td>
    </tr>
  </c:forEach>
</c:if>

有关完整代码,请查看jsp iterate over list