如何使用此代码检查下拉列表是否没有值?
<td width="168"><select name="OrgType" class="txtbox" tabindex="1">
<option value="1">Please choose...</option>
<%
Iterator it2 = Org_Items2.iterator();
while (it2.hasNext())
{
OrganizationItems orgItem2 = (OrganizationItems) it2.next();
//EMSItems newsItem4 = new EMSItems();
%>
<option value=<%=orgItem2.getOrgTypeId()%>><%=orgItem2.getOrgTypeName()%></option>
<%
}
%>
</select></td>
<td width="120">
<%
if (errors.containsKey("OrgType"))
{
out.println("<span class=\"warning\">" + errors.get("OrgType") + "</span>");
}
%>
</td>
然后验证码
long OrgType = Integer.parseInt(req.getParameter("OrgType"));
if ("1".equals(OrgType))
{
errors.put("OrgType", "Required");
}
else if(req.getParameter("OrgType") != null && !"".equals(req.getParameter("OrgType")))
{
long OrgTypeId = Integer.parseInt(req.getParameter("OrgType"));
emsItem.setOrgTypeId(OrgTypeId);
}
我在我的标题页中使用了 usebean 标记
<%@ page import="java.util.Iterator"%>
<%@ page import="data_registration_items.OrganizationItems"%>
<jsp:useBean id="Org_Items2" scope="request" type="java.util.List" />
但是当我尝试将下拉列表的值保留为“请选择...”时,我收到了错误
java.lang.InstantiationException: bean Org_Items not found within scope
org.apache.jsp.WEB_002dINF.jsp.organization_002dregistry_jsp._jspService(organization_002dregistry_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
web_registration.OrganizationServlet.doPost(OrganizationServlet.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
web.SecurityFilter.doFilter(SecurityFilter.java:55)
如果下拉列表传递了正确的值,如何正确验证?
我试图删除标题中的 usebean。在我的 servlet 中,我已经有了
List<OrganizationItems> orgItems2 = new SetOrganizationType().OrgTypeList();
req.setAttribute("Org_Items2", orgItems2).
在我的 doGet 方法下...
在我的jsp页面中,我输入了相同的代码并且错误说
Org_Items2 cannot be resolved
在选项 2 中我也尝试过,但发生错误
java.lang.ClassCastException: java.util.LinkedList cannot be cast to java.util.ArrayList