Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

html - why doesnt my jsp request.getParameter() get the data?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...