【问题标题】:hidden input in JSP returns null in the ServletJSP 中的隐藏输入在 Servlet 中返回 null
【发布时间】:2015-01-03 05:05:53
【问题描述】:

这是我的jsp中的表单:

    <form id="withdrawFromAccountForm" action="${pageContext.request.contextPath}/ActionServlet" method="post" enctype="text/plain">
        <input type="hidden" name="jspId" value="viewClientDetails" /> 
        <input type="submit" class="submit" value="Enter" />

    </form>

这是我的 servlet 中的代码:

String whatJsp = request.getParameter("jspId");     
if (whatJsp.equals("viewClientDetails"))
    {
        //code ..
    }

当我点击 JSP 中的提交按钮时,servlet 转到检查的 if 语句 如果 jsp 是带有隐藏输入的“viewClientDetails” jsp,但该输入给出 null ...

有人知道问题出在哪里吗? 谢谢。

【问题讨论】:

  • 您是如何阅读该输入的?请说明whatJsp 是如何初始化的。
  • 我编辑了它。现在你可以看到了。
  • 你为什么在你的&lt;form&gt;中使用enctype="text/plain"?
  • 好的,我刚刚删除了 enctype="text/plain" 并且它起作用了..

标签: jsp servlets input hidden


【解决方案1】:

问题可能出在这里:

<form ... enctype="text/plain">
          ^ here

来自w3schools:

enctype 属性指定表单数据在提交到服务器时应如何编码。

text/plain:空格转换为“+”符号,但不编码特殊字符

使用enctype 时,您的服务器可能无法识别或无法解析属性。删除它或使用默认值application/x-www-form-urlencoded。

【讨论】:

    猜你喜欢
    • 2020-05-21
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    • 2019-01-01
    • 2018-02-04
    • 2014-10-01
    • 2011-02-01
    • 2019-08-03
    相关资源
    最近更新 更多