2013-08-19 19 views
0

到Servlet的我想要得到的bfnsCode選擇標籤平變化的價值無需刷新頁面的servlet。還有taxtCode的值。我應該怎麼做?這裏是我的代碼...獲得在JSP中選擇的值不刷新頁面

JSP:

<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> 
     <c:forEach var="bircode" items="${birtypelist}"> 
     <option value="${bircode.bfnsCode}">${bircode.bfnsCode}</option>        
     </c:forEach> 
    </select> 
    <br><br> 

<label style="font-size: 17px;">Tax Type</label><br>    
    <select name="taxtCode" id="taxtCode" class="sel" style="width: 245px; margin-left: 0;"> 
     <option selected="selected" value=""></option> 
     <c:forEach var="taxcode" items="${taxtypelist}"> 
     <option value="${taxcode.taxtCode}">${taxcode.taxtCode}</option> 
     </c:forEach>                       
    </select> 
    <br><br> 

<label style="font-size: 17px;">Account Code</label><br>  
    <select name="taxtDesc" id="taxtDesc" class="sel" style="width: 245px; margin-left: 0;"> 
     <option selected="selected" value=""></option> 
     <c:forEach var="taxdesc" items="${taxdesclist}"> 
     <option value="${taxdesc.taxtDesc}">${taxdesc.taxtDesc}</option> 
     </c:forEach>                      
    </select> 

的servlet:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    TblBIRFormNoDAO birdao = DAOFactory.getDaoManager(TblBIRFormNo.class); 
    List<TblBIRFormNo> birtypelist = birdao.getAllBirFormNumber(); 
    request.setAttribute("birtypelist", birtypelist); 

    String bir = request.getParameter("bfnsCode"); 
    TblTaxTypeDAO taxdao = DAOFactory.getDaoManager(TblTaxType.class); 
    if(bir != null){ 
     Debugger.print("BFNSCODE : "+bir); 
     List<TblTaxType> taxtypelist = null; 
     taxtypelist = taxdao.findAlltaxtCode(bir); 
     request.setAttribute("taxtypelist", taxtypelist); 
    } 

    String tax = request.getParameter("taxtCode"); 
    TblTaxTypeDAO tdao = DAOFactory.getDaoManager(TblTaxType.class); 
    if(tax != null){ 
     Debugger.print("TAXCODE : "+tax); 
     List<TblTaxType> taxdesclist = tdao.findAlltaxtDesc(bir, tax); 
     request.setAttribute("taxdesclist", taxdesclist); 
    } 

    request.getRequestDispatcher("/servlet-test.jsp").forward(request, response); 
} 

從這個代碼中的servlet請求的getParameter給出了一個空值。當用戶在下拉列表中選擇一個值時如何獲得正確的值?

PS

第二個下拉是基於第一和第三下拉是基於這樣2號2樓和3下拉是空的時刻,因爲我沒有得到參數bfnsCode的價值(第一下降)。請幫助我,我非常需要這個。

+0

使用AJAX調用servlet的無需重新加載網頁 –

+0

你能幫我做基於此代碼的AJAX調用。我對此毫不知情。 – RMsplace

+0

你是否編輯過這篇文章?我看不出有什麼不同,說我需要2k的聲望來評論它。 – RMsplace

回答

1

如果你是新來阿賈克斯我可以使用jQuery,這是很容易做到的阿賈克斯它。 Ajax get petition。該文檔是非常簡單易懂