【问题标题】:how to get the values of a entire table having text and checkbox fields jsp to servlet如何获取具有文本和复选框字段jsp到servlet的整个表的值
【发布时间】:2017-07-09 14:44:14
【问题描述】:

我有一个jsp,它遍历一个列表,打印名字、姓氏和付费 (Checkbox)。所有这些值都来自 oracle DB。付费复选框是可编辑的(因此,用户可以选中/取消选中checkbox)。我在获取从jspservlet 的所有更新值时遇到问题。我需要知道如何使用 checkbox 更新的值将整个列表返回到 servlet。请告诉我。

JSP 代码 sn-p.

<c:forEach items="${nameList}" var="nameObj">  
  <tr>  
    <td><label>${nameObj.firstName}</label></td>  
    <td><label>${nameObj.lastName}</label></td>  
    <c:if test="${nameObj.paid}">  
        <td><input type="checkbox" name="paid" id="paid" checked ></td>  
  </c:if>  
  </tr>  
</c:forEach> 

【问题讨论】:

    标签: java jsp servlets checkbox jstl


    【解决方案1】:

    您将此代码用作

      <c:forEach items="${nameList}" var="nameObj">  
           <tr>  
          `<td><label>`FirstName`</label><input type="text" name="firstName" value="${nameObj.firstName}"/></td>`  
          `<td><label>`LastName:`</label><input type="text" name="lastName" value="${nameObj.lastName}"/></td>`  
    
      <c:if test="${nameObj.paid}">  
           <td><input type="checkbox" name="paid" id="paid" checked /></td>  
        </c:if>  
        </tr>  
    

    【讨论】:

    • 谢谢。现在,我如何在 servlet 中获取 firstName、lastName 和paid 字段的值。
    • @Javauser try inside servlet String firstname=request.getParameter("firstName");以同样的方式,您还可以从 jsp 到 servlet 获取 lastName 和 Checkbox 字段的值
    猜你喜欢
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多