JSP没有在bean中查找属性

时间:2011-05-31 19:21:41

标签: java jsp javabeans

我的JSP给出了一个错误,表明它无法在DTO中找到属性,但在DTO中属性确实存在。以下是错误:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: An exception occurred processing JSP page /addPos.jsp at line 101

    98:                         
    99:                             --%>
    100: 
    101:                             ${dt.date}
    102: 
    103:                         
    104:                         

    Stacktrace:
        org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

    root cause

    javax.el.PropertyNotFoundException: Property 'date' not found on type p1.dateDto
        javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:193)
        javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:170)
        javax.el.BeanELResolver.property(BeanELResolver.java:279)
        javax.el.BeanELResolver.getValue(BeanELResolver.java:60)
        javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
        org.apache.el.parser.AstValue.getValue(AstValue.java:118)
        org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
        org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)
        org.apache.jsp.addPos_jsp._jspx_meth_c_005fforEach_005f0(addPos_jsp.java:227)
        org.apache.jsp.addPos_jsp._jspService(addPos_jsp.java:168)
        org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

这是dateDto类:

package p1;
import java.sql.Date;

/**
 *
 * @author kk
 */
 public class dateDto
 {
     private Date date;

     public dateDto()
     {
     }

     public dateDto(Date date)
    {
         this.date =date;
     }


    public Date getDateDto()
     {
         return this.date ;
     }
 }

以下是dateDao:

package p1;

/**
 *
 * @author kk
 */
import java.sql.*;
import java.util.*;

public class dateDao {

    private List<dateDto> dateList;
    private String dbUrl = "jdbc:mysql://localhost/mvs_db";
    private String dbDriver = "com.mysql.jdbc.Driver";
    private String dbUser = "root";
    private String dbPwd = "";

    public dateDao() {
    }

    public List<dateDto> getDateList() {
        dateList = new ArrayList<dateDto>();
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;

        try {//trying to load the database driver and establish a connection to the database
            Class.forName(dbDriver);//loading the database driver
            con = DriverManager.getConnection(dbUrl, dbUser, dbPwd);//establishing a connection to the database
            //pw.println("connection established");//output if connection is established
        } catch (Exception e) {
            e.printStackTrace();//printing the exception error trace
        }

        try {

            stmt = con.createStatement();
            rs = stmt.executeQuery("Select vote_date from voting_date");

            while (rs.next()) {
                java.sql.Date date = rs.getDate("vote_date");
                dateDto s = new dateDto(date);
                dateList.add(s);
            }

        } catch (Exception e) {
            System.out.println(e);
        } finally {
            try {
                if (con != null) {
                    con.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return dateList;
    }
}

我实际上是从mysql数据库中检索日期类型值并在下拉列表中显示。

JSP代码如下:

    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:useBean id="dtb" scope="session" class="p1.dateDao"/>
<%--
    Document   : addCamp
    Created on : May 20, 2011, 11:28:31 AM
    Author     : ken
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <style type="text/css">
            body {
                background-color:#AFC7C7;
                padding: 0;
                margin: 0;
            }
            div.wrapper {
                margin-left: 10%;
                margin-right: 10%;
                background-color:#6D7B8D;
                height: 607px;
                padding-top:0px;
                border: thin solid #000000;
            }

            div#image{
                padding-top:1%;
                padding-bottom:1%;
            }
            div#adminlogin{
                width:35%;
                height:40%;
                background-color:#AFC7C7;
                border-width:thin;
                border-style:solid;
                border-color:#000000;
                margin: 0 auto;
                text-align:left;
                overflow: hidden;
                padding: 5px;
            }

            hr {
                height:1px;
                color:#000000;
                background-color:#000000;
                width:99%;
                margin-left: 0 ;
                margin-right: auto ;
                border-style:solid;
            }

            .inputtext {
                width: 200px;
                height: 30px;
                Font-Family:Arial;
                Font-Size:18px
            }

        </style>

        <script language="javascript" type="text/javascript">
            function clearText(field){

                if (field.defaultValue == field.value) field.value = '';
                else if (field.value == '') field.value = field.defaultValue;

            }

        </script>
    </head>
    <body>
        <div class="wrapper">
            <div id="image">
                <p>
                    <img src="${pageContext.request.contextPath}/images/logo.gif"
                         alt="banner"
                         width=100%
                         height="100"
                         /></p>
            </div><!--end of image div-->
            <div id=adminlogin >
                <p style="text-align:center">Adding Voting Position</p>
                <hr/>
                <form method=POST id="pos" action="${pageContext.request.contextPath}/getPos">
                    <p/>
                    <%--The textfield for hostel name--%>
                    <label>Position<input type="text" id="pos"  name="position" value="" class="inputtext"
                                             onFocus="clearText(this)" onBlur="clearText(this)"/></label><br/>
                    <br/>
                    <label>Voting Date <select name="dates" size="1" id="pos" class="inputtext"
                                               onFocus="clearText(this)" onBlur="clearText(this)">
                        <c:forEach items="${dtb.dateList}" var="dt">
                            <%--<option value="1"><c:out value="${cam.campnm}"/></option>--%>

                            <option>${dt.date}</option>

                        </c:forEach>
                        </select></label>
                        <br/>
                        <br/>
                    <input type="submit" value="Add" style="font-size:14pt; margin-left: 158px; height: 30px;"/>

                </form>
                <p STYLE="color : #E41B17;">${message}</p>
                <c:remove var="message" scope="session" />



            </div><%--end of admin login div--%>
            <p style="text-align: center"><a href=adminHome.jsp>Home</a> <a href=index.jsp>Logout</a></p>
        </div>
    </body>
</html>

可能是什么问题?

2 个答案:

答案 0 :(得分:4)

您错过了dateDto

中的标准制定者/获取者

成功

public class dateDto
 {
     private Date date;

     public dateDto()
     {
     }

     public dateDto(Date date)
     {
         this.date =date;
     }


    public Date getDate()
     {
         return this.date ;
     }

     public Date setDate(Date d)
     {
          this.date  = d;
     }
 }

答案 1 :(得分:0)

问题是您正在寻找财产date,而您的财产实际上已命名为dateDto