项目未使用servlet显示在下拉列表中

时间:2013-08-13 08:23:54

标签: java jsp servlets

我为下拉列表创建了一个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>

1 个答案:

答案 0 :(得分: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;
    }
}

TblBIRFormNo class

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>

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