2

我正在用struts开发一个在线图书库应用程序......

我有一个用户表单,用户将在其中输入他的详细信息,例如名字,姓氏等,还有一个书籍列表,他将在其中选择一些他想要的书籍..稍后我想将这些详细信息插入到 2 个表中..即 obl_users 中的用户详细信息以及用户在 users_books 中选择的书籍。

我将以下代码用于列表..

<% 
if(request.getAttribute("booksNameList") != null) { 
%>
    <html:select property="displayBooks" multiple="true" size="5">
    <logic:iterate id="booksNameList" name="booksNameList" scope="request"> 
        <html:option value="${booksNameList.bookId}" ><bean:write name="booksNameList" property="longTitle" /></html:option>

    </logic:iterate>
    </html:select>

<%
}
%>

最初,当用户请求表单时,表单将预先填充列表将数据库中的所有书籍名称..我不确定我为在 ie 的值部分中获取书籍 ID 而编写的代码 value="${booksNameList.bookId}"..

在我的 addUser() 中,我想像这样遍历用户选择的书籍..

for (int i = 0; i < selectedBooks.length; i++) {

                //insertBooks.setInt(1, generatedKeys.getInt(1));
                //insertBooks.setInt(2, Integer.parseInt(selected[i]));

                //insertBooks.addBatch();
            }

但为此如何让用户选择书籍..

这是我的 user.java

public class User extends ActionForm {

    private int userId;
    private String firstName;
    private String lastName;
    private String middleName;
    private String username;
    private String password;
    private String contactNumber;
    private String membershipNumber;
    private String role;
    private String email;
    private String address;
    private String comments;
    private String dateOfBirth;
    private int oblStatus;
    private String createdDate;
    private String updatedDate;
    private String createdBy;
    private String updatedBy;
    private String displayBooks;

    public int getUserId() {
        return userId;
    }
    public void setUserId(int userId) {
        this.userId = userId;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getMiddleName() {
        return middleName;
    }
    public void setMiddleName(String middleName) {
        this.middleName = middleName;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getContactNumber() {
        return contactNumber;
    }
    public void setContactNumber(String contactNumber) {
        this.contactNumber = contactNumber;
    }
    public String getMembershipNumber() {
        return membershipNumber;
    }
    public void setMembershipNumber(String membershipNumber) {
        this.membershipNumber = membershipNumber;
    }
    public String getRole() {
        return role;
    }
    public void setRole(String role) {
        this.role = role;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getAddress() {
        return address;
    }
    public void setAddress(String address) {
        this.address = address;
    }
    public String getComments() {
        return comments;
    }
    public void setComments(String comments) {
        this.comments = comments;
    }
    public String getDateOfBirth() {
        return dateOfBirth;
    }
    public void setDateOfBirth(String dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }
    public int getOblStatus() {
        return oblStatus;
    }
    public void setOblStatus(int oblStatus) {
        this.oblStatus = oblStatus;
    }
    public String getCreatedDate() {
        return createdDate;
    }
    public void setCreatedDate(String createdDate) {
        this.createdDate = createdDate;
    }
    public String getUpdatedDate() {
        return updatedDate;
    }
    public void setUpdatedDate(String updatedDate) {
        this.updatedDate = updatedDate;
    }
    public String getCreatedBy() {
        return createdBy;
    }
    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }
    public String getUpdatedBy() {
        return updatedBy;
    }
    public void setUpdatedBy(String updatedBy) {
        this.updatedBy = updatedBy;
    }
    public String getDisplayBooks() {
        return displayBooks;
    }
    public void setDisplayBooks(String displayBooks) {
        this.displayBooks = displayBooks;
    }



}

书豆类:

private String bookId;
    private String longTitle;
    private String shortTitle;
    private String isbn;
    private String dateOfPublication;
    private String noOfPages;
    private String boundType;
    private String dvdAvailability;
    private String noOfAvailableCopies;
    private int oblStatus;
    private String createdDate;
    private String updatedDate;
    private String createdBy;
    private String updatedBy;
    private String displayAuthors;
    private int[] authorIds;

请指导我......我对struts完全陌生

4

2 回答 2

3

您必须将“displayBooks”属性作为字符串数组;

private String[] displayBooks;

由于您想在表单上选择多个值,因此 Array 或 ArrayList 可能是唯一更好的选择。

于 2013-10-07T09:41:25.930 回答
0

在这里 你可以找到一个如何做的例子或获取一个项目列表

于 2014-11-21T12:26:56.520 回答