【发布时间】:2012-01-21 22:56:39
【问题描述】:
我有一个带有两个下拉位置和部门的 jsp。
部门下拉列表的值是根据位置值通过 Ajax 填充的。
但是当我尝试保存页面时,如果选择了部门下拉列表中的第一项,我将无法访问部门下拉列表的值。
但是如果选择了第 2 项或第 3 项,则可以从 servlet 访问它。
<form id="form1" name="crtdocfrm" action="CreateLocation" method="post">
<fieldset width="50%">
<legend>Division</legend>
<table id="table1">
<tr class="tr_stylebutton">
<td>Location Name</td>
<td><select name="locName" onChange="showDept(this.value)">
<option value="-1">--select--</option>
<%
Iterator itrLocation = arlLocation.iterator();
while (itrLocation.hasNext()) {
%>
<option value=<%=itrLocation.next()%>><%=itrLocation.next()%>
</option>
<%}%>
</select></td>
</tr>
<tr class="tr_stylebutton">
<td>Department Name</td>
<td>
<select name="ddDeptName" onChange="alert(this.value)"></select>
</td>
</tr>
<tr class="tr_stylebutton">
<td>Division ID</td>
<%
LocationPolulate lp = new LocationPolulate();
int Div_Id = lp.DivisionId();
%>
<td><input type="text" name="divID" disabled="true" value=<%=Div_Id + 1%>/></td>
</tr>
<tr class="tr_stylebutton">
<td>Division Name</td>
<td><input type="text" name="divName" value=""/></td>
</tr>
</table>
<table border="0" width="55%" align="left" id="table-button">
<tr class="tr_stylebutton">
<td align="right"><input type="submit" value="Save" class="button"/></td>
<td align="left"><input type="submit" value="Cancel" class="button"/></td>
</tr>
</table>
</fieldset>
<br/>
</form>
小服务程序
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
int intLocId = Integer.parseInt(request.getParameter("locName"));
String strDivNm = (String) request.getParameter("divName");
int intDeptId = Integer.parseInt(request.getParameter("ddDeptName"));
LocationPolulate lp = new LocationPolulate();
int Res = lp.InsertDivision(strDivNm, intLocId, intDeptId);
if (Res == 0) {
request.setAttribute("Errmsg", "Error Cannot Save Division");
RequestDispatcher dis1 = getServletContext().getRequestDispatcher("/AddDivision");
dis1.forward(request, response);
} else {
int Div = lp.DivisionId();
request.setAttribute("succmsg", "Successfully saved Division with division id:" + Div);
RequestDispatcher dis1 = getServletContext().getRequestDispatcher("AddDivision.jsp");
dis1.forward(request, response);
}
}
有什么想法吗?
【问题讨论】:
-
函数 stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { var showdata = xmlHttp.responseText; var strar = showdata.split(":"); if(strar.length==1) { document.getElementById("locName").focus(); alert("请选择位置 ID"); } else if(strar.length>1) { option=new Option("---Select---", -1); document.crtdocfrm.ddDeptName.options[0]=选项; for(var i=0;i
-
只是想知道,你觉得你的代码可读吗?
-
您是否知道您在选项标记迭代器中为每个选项调用了两次
.next()方法,一次用于值,一次用于显示值? -
@Alivia 请添加代码作为问题的一部分,而不是评论。
-
“我无法访问该值”是什么意思。 intDeptId 的值是多少? request.getParameter("ddDeptName") 的值是多少?