在request.getParameter()中获取单选按钮的空值

时间:2014-12-20 22:23:39

标签: jquery jsp servlets

enter code here你能否告诉我哪里出错了,我不明白为什么我得到request.getParameter(“IDclass”)的空值,其中IDclass是我的单选按钮的name属性。以下是代码,请运行它并告诉我。感谢您的帮助。

/**
 * @see HttpServlet#HttpServlet()
 */
public Salary_Servlet() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    //DOA data = new DOA();
    //String id = request.getParameter("IDclass").toString();
    //List<PaycheckBean> paylist = data.getpay();
    PrintWriter out = response.getWriter();             
    //Gson gson = new Gson();
    //out.println(gson.toJson(paylist));
    out.print(request.getParameter("IDClass"));
}

}

我的JSP在下面             
    

<div id="div1" class="right_side">
    Hello World
</div>  

<script>
$(document).ready(function(){
    $('#getdata').click(function(){
        var username = $('uname').val();
        var password = $('pword').val();
        console.log("Wekcome");
        $.ajax({
            url : 'http://localhost:8080/Practice_App/Login_Servlet',
            async : 'true',
            data : {username : name, password : password},
            type : 'POST',
            dataType : 'JSON',
            success : function(data) {
                var table = document.createElement("table");

                for(var j=0;j<data.length;j++){
                    var tableRow = document.createElement("tr");
                    var EmployeeID = document.createElement("td");
                    var radiospace = document.createElement("input");
                    radiospace.setAttribute("type", "radio");
                    radiospace.setAttribute("name", "IDclass")
                    radiospace.setAttribute("value", j);
                    var Name = document.createElement("td");
                    var Phonenumber = document.createElement("td");

                    EmployeeID.innerHTML = data[j].EmployeeID;
                    Name.innerHTML = data[j].Name;
                    Phonenumber.innerHTML = data[j].Phonenumber;
                    radiospace.innerHTML = "Hello";

                    tableRow.appendChild(EmployeeID);
                    tableRow.appendChild(Name);
                    tableRow.appendChild(Phonenumber);
                    tableRow.appendChild(radiospace);

                    table.appendChild(tableRow);

                }
                document.getElementById("tableDiv").appendChild(table);

                $('input:radio[name="IDclass"]').change(function(){
                    //var id = $('IDclass').val();
                    for(var i=0;i<data.length;i++){
                        if ($(this).is(':checked') && $(this).val() == i) {
                            // append goes here
                            console.log("You choose "+(i+1));
                            $.ajax({
                                url: "http://localhost:8080/Practice_App/Salary_Servlet",
                                async : 'true',
                                type : 'POST',
                                dataType : 'JSON',
                                success : function(data) {
                                    var table = document.createElement("table");
                                    for(var k=0;k<data.length;k++){
                                        var tableRow = document.createElement("tr");
                                        var ID = document.createElement("td");
                                        var Month = document.createElement("td");
                                        var Salary = document.createElement("td");

                                        ID.innerHTML = data[k].ID;
                                        Month.innerHTML = data[k].Month;
                                        Salary.innerHTML = data[k].Paycheck;

                                        tableRow.appendChild(ID);
                                        tableRow.appendChild(Month);
                                        tableRow.appendChild(Salary);

                                        table.appendChild(tableRow);                                        
                                    }
                                    document.getElementById("div1").appendChild(table); 
                                }
                            });
                        };
                    };                      
                })                      
            },
            error : function(e) {
                console.log(e);
            }
        });
    });
});

$("#IDsearch").keyup(function(){
     var term = $(this).val();
     if(term != ""){
         $("#tableDiv tr").hide();
         $("#tableDiv td").filter(function(){
             return $(this).text().toLowerCase().indexOf(term)>-1;  
             }).parent("tr").show();
     }
     else
         {
         $("#tableDiv table>tr").show();
         }

  }); 
</script>

enter code here

0 个答案:

没有答案