我有我的第一个下拉列表id="bfnsCode",我想将该值用于我的下一个下拉列表 id="taxtCode" 以便能够根据第一个下拉列表显示新的一组值。这是我的代码:
<div class="BIR" style="display: none;">
<div>
<label style="font-size: 17px;">BIR-Form Number</label><br>
<select name="bfnsCode" id="bfnsCode" class="sel" style="width: 245px; margin-left: 0;">
<option selected="selected" value=""></option>
<%
TblBIRFormNoDAO birdao = DAOFactory.getDaoManager(TblBIRFormNo.class);
HttpSession live = request.getSession(true);
TblUserInformation user = (TblUserInformation) live.getAttribute("user");
List<TblBIRFormNo> birtypelist = null;
if(user.getRcoCode() != null){
birtypelist =birdao.getAllBirFormNumber();
}else{
}
String birtypeoptions = "";
if( birtypelist!=null) {
if( birtypelist.size()>0 ) {
for(int i=0; i<birtypelist.size();i++) {
TblBIRFormNo taxtype = (TblBIRFormNo) birtypelist.get(i);
birtypeoptions += "<option value='"+taxtype.getBfnsCode()+"'>"+taxtype.getBfnsCode()+"</option>";
taxtype = null;
}
}
}
birdao = null;
birtypelist = null;
%>
<%=birtypeoptions%>
</select>
<br><br>
<label style="font-size: 17px;">Tax Type</label><br>
<select name="taxtCode" id="taxtCode" class="sel" style="margin-left: 0;">
<option selected="selected" value=""></option>
<%
TblTaxTypeDAO taxdao = DAOFactory.getDaoManager(TblTaxType.class);
List<TblTaxType> taxtypelist = null;
String tax = request.getParameter("bfnsCode");
Debugger.print("test : "+tax);
if(tax != null){
taxtypelist = taxdao.findAlltaxtCode(tax);
}else{
taxtypelist = taxdao.getAllTaxTypes();
}
String taxtypeoptions = "";
if( taxtypelist!=null) {
if( taxtypelist.size()>0 ) {
for(int i=0; i<taxtypelist.size();i++) {
TblTaxType taxtype = (TblTaxType) taxtypelist.get(i);
taxtypeoptions += "<option value='"+taxtype.getTaxtCode()+"'>"+taxtype.getTaxtCode()+"</option>";
taxtype = null;
}
}
}
taxdao = null;
taxtypelist = null;
%>
<%=taxtypeoptions%>
</select>
如您所见,我在下拉税中使用request.getParameter("bfnsCode")调用该值,但它给了我一个空值。
ListBIRFormNo.java(用于c:forEach的 servlet )
public class ListBIRFormNo extends HttpServlet {
private static final long serialVersionUID = 1L;
private List<TblBIRFormNo> birtypelist;
public List<TblBIRFormNo> getTblBIRFormNo() {
return birtypelist;
}
public void setTblBIRFormNo(List<TblBIRFormNo> birtypelist) {
this.birtypelist = birtypelist;
}
private HttpServletRequest request;
public void setServletRequest(HttpServletRequest request){
this.request = request;
}
public String execute(){
Debugger.border();
try{
TblBIRFormNoDAO birdao = DAOFactory.getDaoManager(TblBIRFormNo.class);
HttpSession live = request.getSession(true);
TblUserInformation user = (TblUserInformation) live.getAttribute("user");
if(user.getRcoCode() != null){
birtypelist =birdao.getAllBirFormNumber();
}else{
//no-op
}
//expose 'birtypelist' as an attribute
request.setAttribute("birtypelist", birtypelist);
}catch(Exception e){
e.printStackTrace();
Debugger.print(" EXCEPTION :"+e.getStackTrace());
Debugger.endDebug(this.getClass().toString());
Debugger.border();
}
Debugger.border();
return null;
}
}