我的 JSP 中有 html 可以提出简单的问题,并且有下拉框供用户选择他们的回答。我还设置了默认响应,以防他们决定只点击下一个,但是我总是返回 null。JSP:
<div id="startQrtQuestion" align="left">1) When did you first arrive here?</div>
<div id="startQrtResponse" align="left">
<select name="quarterStart">
<option value="summer">Summer Quarter</option>
<option value="fall" selected="selected">Fall Quarter</option>
</select>
</div>
<div id="programQuestion" align="left">2) What program are you taking?</div>
<div id="programResponse" align="left">
<select name="programSelect">
<option value="bscs" selected="selected">BSCS</option>
<option value="bstm">BSTM</option>
<option value="bsgd">BSGD</option>
<option value="bswd">BSWD</option>
</select>
</div>
<div id="extendedQuestion" align="left">3) Will you be staying extra quarters?</div>
<div id="extendedResponse" align="left">
<div name="extendedStayResponses">
<input type="checkbox" name="extendedStay" id="extendedStay"/>Yes
</div></br>
<div id="extendedFullTime" style="display:none">
Full Time:<select name="extraFullQuarters">
<option value="0" selected="selected">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>(Taking 12 Credits or More)
</div></br>
<div id="extendedPartTime" style="display:none">
Part Time:<select name="extraPartQuarters">
<option value="0" selected="selected">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
</div>
这一切都包含在一个表单中,该表单将调用我的 servlet 中的 post 方法。但是,当我像这样检索这些值时:
String startQuarter = request.getParameter("quarterStart");
String programSelect = request.getParameter("programSelect");
String extendedStay = request.getParameter("extendedStay");
我得到空指针异常。该值是否不会自动设置为我默认选择的选项?
我没有正确访问这些输入吗?