JSP在bean中找不到属性 [英] JSP not finding property in bean

查看:89
本文介绍了JSP在bean中找不到属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My JSP gives an error showing that it is not able to find a property in a DTO and yet in the DTO the property is really there. Below is the error:


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类:

Here is the dateDto class:

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:

Below is the 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数据库中检索Date类型的值,并显示在下拉列表中.

I'm actually retrieving Date type values from a mysql database and displying in a dropdown list.

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>

可能是什么问题?

推荐答案

您错过了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;
     }
 }

这篇关于JSP在bean中找不到属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆