0

我为下拉列表创建了一个 servlet。这是代码..

DDBIRFormNo.java(servlet)

public class DDBIRFormNo extends HttpServlet {
private static final long serialVersionUID = 1L;

    @Override
    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);
            request.getRequestDispatcher("/WEB-INF/rcmoduleIssue-eReceipt-ROR.jsp").forward(request, response);  
    }
}

我不知道我是否错过了什么。

rcmoduleIssue-eReceipt-ROR.jsp:

<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>
4

1 回答 1

0

你能发布你的错误吗,你得到了吗?这将有助于我们发现问题。我尝试创建相同的结构并实现 servlet,然后在下拉列表中设置值及其工作。下面是我尝试过的代码,DDBIRFormNo servlet

public class DDBIRFormNo extends HttpServlet {

    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        List<TblBIRFormNo> birtypelist = this.getAllBirFormNumber();
        request.setAttribute("birtypelist", birtypelist);
        request.getRequestDispatcher("/WEB-INF/rcmoduleIssue-eReceipt-ROR.jsp").forward(request, response);
    }

    private List<TblBIRFormNo> getAllBirFormNumber(){
        List<TblBIRFormNo> lTblBIRFormNo = new ArrayList<TblBIRFormNo>();
        TblBIRFormNo birFormNo = new TblBIRFormNo();
        birFormNo.setBfnsCode("123");
        lTblBIRFormNo.add(birFormNo);

        birFormNo = new TblBIRFormNo();
        birFormNo.setBfnsCode("456");
        lTblBIRFormNo.add(birFormNo);

        birFormNo = new TblBIRFormNo();
        birFormNo.setBfnsCode("789");
        lTblBIRFormNo.add(birFormNo);

        birFormNo = new TblBIRFormNo();
        birFormNo.setBfnsCode("012");
        lTblBIRFormNo.add(birFormNo);
        return lTblBIRFormNo;
    }
}

TblBIRForm无类

public class TblBIRFormNo {

    public String bfnsCode = null;

    /**
     * @return the bfnsCode
     */
    public String getBfnsCode() {
        return bfnsCode;
    }

    /**
     * @param bfnsCode
     *            the bfnsCode to set
     */
    public void setBfnsCode(String bfnsCode) {
        this.bfnsCode = bfnsCode;
    }
}

WEB-INF/rcmoduleIssue-eReceipt-ROR.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<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>
</body>
</html>

上面的示例是根据您的代码及其工作正常

于 2013-08-13T09:22:23.713 回答