【问题标题】:Getting Null value from request.getParameter() [duplicate]从 request.getParameter() 获取 Null 值
【发布时间】:2012-05-23 16:41:45
【问题描述】:

在我的应用程序中,在加入的帮助下,我在我的 jsp 页面中显示动态值,如下所示:

<%  while(rs.next()){ %>
<td><input type="checkbox" name="chkName" onclick="selectall()"></td> 
<td><input type="text"  name="empId" value="<%= rs.getString(1)%> "   disabled="disabled"  maxlength="10"></td>
<td><input type="text" name="device" value="<%= rs.getString(2)%>"   disabled="disabled" maxlength="10"></td>
<td><input type="text"  name="features" value="<%= rs.getString(3)%>"  disabled="disabled" maxlength="60"></td>
<td><input type="password" name="password" disabled="disabled"></td>
<td><input type="text"  name="policyName" value="<%= rs.getString(4)%>"  disabled="disabled" maxlength="10"></td>
</tr>
<% } 
%>

每当从另一个 servlet(因为我想显示从这个 jsp 到另一个 jsp 的获取)我调用request.getParameter("empId"),它正在获取“NULL”值。我认为,我必须使用 set(@987654323 @ 或 request.setParameter())。

任何建议将不胜感激。

【问题讨论】:

  • 为什么这里有一个 i 标签? name="empId"

标签: jsp servlets


【解决方案1】:

可能是因为 disabled 属性..也许你可以用 readonly 代替它?

【讨论】:

  • 你能显示一些代码吗?它应该如下所示:。如果您删除 disabled 属性,您将不会得到 NULL 对吗?
【解决方案2】:

你的意思是说你需要在 2 个 jsp 页面之间传递值吗?然后您可以通过将其设置在隐藏的输入字段中或在会话中设置来使用它...

检查这是否对您有帮助...Using request.setAttribute in a JSP page

【讨论】:

    【解决方案3】:

    另一种简单的方法。

    您可以添加隐藏类型。

    <td><input type="text" value="<%= rs.getString(1)%> "   disabled="disabled"  maxlength="10"></td>
    <td><input type="hidden"  name="empId" value="<%= rs.getString(1)%> "  maxlength="10"></td>
    

    【讨论】:

      【解决方案4】:

      对于名为 empId 而不是 &lt;i&gt;empId 的字段,请尝试使用 request.getParameter("empID")。希望对您有所帮助,只需重命名表单中的字段

      【讨论】:

        猜你喜欢
        • 2017-12-03
        • 1970-01-01
        • 2012-05-23
        • 2015-04-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-12
        • 1970-01-01
        相关资源
        最近更新 更多