为什么我的jsp request.getParameter()获取数据? [英] why doesnt my jsp request.getParameter() get the data?

查看:146
本文介绍了为什么我的jsp request.getParameter()获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想要使用这些信息从1.jsp中确定2.jsp的输出...

jsfiddle for 1.jsp: http://jsfiddle.net/VWczQ/

  action =/ 2.jsp> 

现在在2.jsp中有这个:

 <%if(request.getParameter(extra)!= null){%> 
<%} else if(request.getParameter(all)!= null){%>
< page:cmsElement id =cmsContentname =/ otcmarkets / traderAndBroker / market-data-vendors / con-all/>
<%} else {%>
< h1>圣洁的东西一切都是空的!!!< / h1>
<%}%>

当我从表单中随机选择一切都为NULL时...



我做错了什么?!?

解决方案

您似乎期待<$已经将HTML输入元素的c $ c> id 属性作为请求参数名称发送。这是错误的。它是作为请求参数名称发送的名称属性。它的值就是在给定输入元素上设置的 attribtue。



因此,例如你的错误检查

  if(request.getParameter(extra)!= null){
//。 ..
}

用于以下单选按钮

 < input type =radioname =choicevalue =extranetid =extra/> 

您需要按名称获取参数 choice 并测试它的值是否为 extranet

  if(extranet.equals(request.getParameter(choice))){
//。 ..
}

至于全部复选框,我很困惑。可以发送两个值,但是您在 if-else 中检查它们。不应该全部在相同的单选按钮组中吗?你不应该删除 else ?无论如何,这一点应该清楚。它是以请求参数名称发送的输入元素 name attribtue,而不是 id 属性。


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?!?

解决方案

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 the name attribute which is been sent as request parameter name. Its value is then the value attribtue which is been set on the named input element.

So, instead of for example your incorrect check

if(request.getParameter("extra") != null) {
    // ...
}

for the following radio button

<input type="radio" name="choice" value="extranet" id="extra"/>

you need to get the parameter by name choice and test if its value is extranet.

if ("extranet".equals(request.getParameter("choice"))) {
    // ...
}

As to the all checkbox, I am confused. It is possible to send the both values, yet you're checking them in an if-else. Shouldn't the all be inside the same radio button group? Shouldn't you remove the else? In any way, the point should be clear. It's the input elements' name attribtue which get sent as request parameter name, not the id attribute.

这篇关于为什么我的jsp request.getParameter()获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆