如何解决JSP在bean中找不到属性
| 我的JSP给出一个错误,表明它无法在DTO中找到属性,但是在DTO中该属性确实存在。下面是错误: 类型例外报告 信息 描述服务器遇到内部错误(),导致服务器无法满足此请求。 例外 org.apache.jasper.JasperException:在第101行处理JSP页面/addPos.jsp时发生异常 98: 99:-%> 100: 101:$ {dt.date} 102: 103: 104: 堆栈跟踪: 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) 根本原因 javax.el.PropertyNotFoundException:在类型p1.dateDto上找不到属性\'date \' 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数据库中检索Date类型的值,并显示在下拉列表中。
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;
}
}
, 问题在于您正在寻找物业date
,而您的物业实际上被命名为dateDto
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。