为什么我的jsp request.getParameter() 没有获取到数据?
我创建了一个表单,用户将在其中选中复选框、选择单选按钮和 1.jsp 中的下拉菜单...
我想使用 1.jsp 中的信息来确定 2.jsp 的输出...
jsfiddle for 1 .jsp: http://jsfiddle.net/VWczQ/
action="/2.jsp">
现在在 2.jsp 中我有这:
<% if(request.getParameter("extra") != null) { %>
<page:cmsElement id="cmsContent" name="/otcmarkets/traderAndBroker/market-data-vendors/wizard-results" />
<% } else if(request.getParameter("all") != null) { %>
<page:cmsElement id="cmsContent" name="/otcmarkets/traderAndBroker/market-data-vendors/con-all" />
<% } else { %>
<h1>holy crap everything is null!!!</h1>
<% } %>
当我从表单中随机选择选项时,所有内容都是 NULL...
我做错了什么?!?
ive created a form in which user will check off checkboxes, select radio buttons, and drop downs in 1.jsp...
i want to use the information from 1.jsp to determine the output of 2.jsp...
jsfiddle for 1.jsp: http://jsfiddle.net/VWczQ/
action="/2.jsp">
now in 2.jsp i have this:
<% if(request.getParameter("extra") != null) { %>
<page:cmsElement id="cmsContent" name="/otcmarkets/traderAndBroker/market-data-vendors/wizard-results" />
<% } else if(request.getParameter("all") != null) { %>
<page:cmsElement id="cmsContent" name="/otcmarkets/traderAndBroker/market-data-vendors/con-all" />
<% } else { %>
<h1>holy crap everything is null!!!</h1>
<% } %>
when i randomly choose options from the form everything is NULL...
what am i doing wrong?!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎期望 HTML 输入元素的 id 属性作为请求参数名称发送。这是错误的。它是作为请求参数名称发送的
name
属性。它的值就是在指定输入元素上设置的value
属性。而不是对
以下单选按钮
因此,您需要按名称
choice
获取参数并测试其值是否为extranet
,进行错误检查。至于
all
复选框,我很困惑。可以发送两个值,但您要在if-else
中检查它们。all
不应该位于同一个单选按钮组内吗?难道你不应该删除else
吗?无论如何,这一点应该很清楚。它是作为请求参数名称发送的输入元素的name
属性,而不是id
属性。You seem to be expecting that the
id
attribute of the HTML input elements is been sent as request parameter name. This is wrong. It's thename
attribute which is been sent as request parameter name. Its value is then thevalue
attribtue which is been set on the named input element.So, instead of for example your incorrect check
for the following radio button
you need to get the parameter by name
choice
and test if its value isextranet
.As to the
all
checkbox, I am confused. It is possible to send the both values, yet you're checking them in anif-else
. Shouldn't theall
be inside the same radio button group? Shouldn't you remove theelse
? In any way, the point should be clear. It's the input elements'name
attribtue which get sent as request parameter name, not theid
attribute.