English 中文(简体)
无法从复选框获得多个值
原标题:Not able to get multiple values from checkbox

我试图从 jsp 页面访问多个复选框值。 但我最后的绑定错误了 。

jsp 页面 :

<c:forEach items="${employees}" var="employee">
                    <tr>
                         <td><spring:checkbox path="selectedMails" value="<c:out value= ${employee.emailid} />"/> </td> 
                        <td><spring:label path="employeeId">${employee.employeeId}</spring:label></td>
                        <td><spring:label path="employeeName">${employee.employeeName}</spring:label></td>
                        <td><spring:label path="emailid" >${employee.emailid}</spring:label></td>
                        <td><spring:label path="reportmanager">${employee.reportmanager}</spring:label></td>

                    </tr>
                </c:forEach>

d至页面

//Invitation Beans
    private String [] selectedMails;

    public String [] getSelectedMails() {
        return selectedMails;
    }
    public void setSelectedMails(String [] selectedMails) {
        this.selectedMails = selectedMails;
    }

i 能够在 jsp 页面上打印 ${employee. emailid/code> 。 但我无法重拾, 需要保存一个以上的值。 请帮助我 。

最佳回答

您应该给您创建的每一复选框路径属性中的数组索引 。

您需要在 Jsp 代码中进行修改 。

<c:forEach items="${employees}" var="employee" varStatus="cnt">
    <tr> 
        <td><spring:checkbox path="selectedMails[${cnt.index}]" value="<c:out value= ${employee.emailid} />"/> </td>  
        <td><spring:label path="employeeId">${employee.employeeId}</spring:label></td> 
        <td><spring:label path="employeeName">${employee.employeeName}</spring:label></td> 
        <td><spring:label path="emailid" >${employee.emailid}</spring:label></td> 
        <td><spring:label path="reportmanager">${employee.reportmanager}</spring:label></td> 
    </tr> 
</c:forEach> 

我觉得这应该适合你

希望这能帮到你

欢呼声。

问题回答

要获得一个以上的值, 您应该有一个相同名称的多个复选框。 在此情况下, 它会作为数组被置于请求中, 您可以以数组的形式获得这个值 。

如果您有单一的复选框, 则会得到单一的值。 如果未选中复选框, 则不会得到任何值 。 如果未选中复选框, 它不会将任何值作为请求的值 。





相关问题
Convert typed-in Text to lowercase

I ve got an index.jsp with [snip] <% String name = request.getParameter("name"); String pass = request.getParameter("pass"); String globalname = "webeng"; String globalpass = "2009"; ...

session transfer issue from Tomcat to ASP.Net

I am using Tomcat to host JSP and using IIS 7.0 to host aspx (C# + .Net 3.5 + VSTS 2008), and I have some session transfer issue from JSP page to ASPX page. JSP page is in one domain and all other ...

Setting the default value in Struts2

I am setting the value(kind of default value) for a drop down select value from action class in a page(given below). When the page loads the value is beig displayed but the other elements of the ...

Evaluate dynamically constructed JSP at runtime

I have a requirement where in the JSP page itself is created by the user and stored in the database. When viewing results we need to render this JSP to the client, evaluating all tags inside this JSP. ...

How to Pack/Encrypt/Unpack/Decrypt a bunch of files in Java?

I m essentially trying to do the following on a Java/JSP-driven web site: User supplies a password Password is used to build a strongly-encrypted archive file (zip, or anything else) containing a ...

JSP exception - class not found (tomcat)

I m setting up an existing application on a new Tomcat 5.5 server connecting to a Postgres database (running on Debian Lenny). When I access it I get a series of stack traces with the following root ...

ArrayList to Table in JSP

I have an ArrayList and i am trying to display it in a table ..... ArrayList rows = .... ..... <table cellspacing="1" cellpadding="4" border="3"> <tr> <TH>...