【问题标题】:Request.getParameter() not working in jsp page using CQRequest.getParameter() 在使用 CQ 的 jsp 页面中不起作用
【发布时间】:2023-04-01 11:59:01
【问题描述】:

我有如下代码

<div>
  <form action="<%= currentNode.getPath() %>.html" method="POST">
         <input type="text" name="test" id="test"/>
         <input type="submit" name="submitt" id="submitt" style="display:none;" /> 
     </form>
</div>

我正在尝试获取现场测试的价值

<%
String name=request.getParameter("test"); 
out.println("value in the string"+name);
%>

但我只得到空值?可能是什么问题?

【问题讨论】:

标签: jsp


【解决方案1】:
<form action="<%= currentNode.getPath() %>.html" method="POST">

您是否将表单发布到 html page 。以及如何在html页面中得到结果

您的form action 属性应该具有servlet 或其他jsp 的url,以便从请求中获取值。

Request是jsp的隐含对象,不是html。

例如,

one.jsp:

        <form name="form1" action="two.jsp" method="POST">
          <input type="text" name="test" id="test"/>
         <input type="submit" name="submitt" id="submitt" style="display:none;" /> 
        </form>

两个.jsp:

<%
String name=request.getParameter("test"); 
out.println("value in the string"+name);
%>

将打印请求中的值。相反,如果您试图在同一页面中获取值而不发布它。可以使用javascript实现它

【讨论】:

  • 即使我删除了 html 它也不起作用
  • 你想在同一个页面中获取 id 还是尝试在不同的页面中发布
  • 在同一个页面中,但在 scriptlet 或 JSTL 标签中,但不在 javascript 中
  • 我的 javascript 中有一个值,我正在尝试在我的 jsp 页面中获取该值。为此,我创建了一个表单。
  • 如果您还有任何疑问,请加入这里chat.stackoverflow.com/rooms/63539/jsp-concepts
猜你喜欢
  • 1970-01-01
  • 2013-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-03
  • 2017-07-20
  • 1970-01-01
相关资源
最近更新 更多