zoukankan      html  css  js  c++  java
  • 菜鸟程序员之路--调错

      今天做了一个很小的web项目,但最后出现的异常让人头皮发麻,最后通过多方查询,最准调试成功,现在将经验分享给大家,希望可以帮到大家;

    1、javax.el.PropertyNotFoundException: Property 'XXX' not found on type java.lang.String

      stuinfo.jsp页面内容如下:

    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <%@ 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>
        
            <table border="1px" width="100%">
        <tr align="center">
            <td>编号</td>
            <td>姓名</td>
            <td>性别</td>
            <td>电话</td>
            <td>生日</td>
            <td>爱好</td>
            <td>简介</td>
            <td>操作</td>
        </tr>
        <c:forEach items="list" var="stu">
            <tr>
                <td>${stu.sid}</td>
                <td>${stu.sname}</td>
                <td>${stu.sgender}</td>
                <td>${stu.phone}</td>
                <td>${stu.birthday}</td>
                <td>${stu.hoby}</td>
                <td>${stu.info}</td>
                <td><a href="#">更新</a>><a href="#">删除</a>></td>
            </tr>
        </c:forEach>
        </table>
    </body>
    </html>
    View Code

      原因:<c:forEach items="list" var="stu">

      解决方式:items的值应该用EL表达式,因此修改为<c:forEach items="${list}" var="stu">,注意括号里不要有空格,var为循环变量。

    2、javax.el.PropertyNotFoundException: Property 'hoby' not found on type StuBean.Student

      Student.java代码如下:

    import java.util.Date;
    public class Student {
        private int sid;
        private String sname;
        private String sgender;
        private String phone;
        private String hoby;
        private String info;
        private Date birthday;
        public Student(){    
        }
        public Student(int sid, String sname, String sgender, String phone,String hoby, String info, Date birthday) {
            super();
            this.sid = sid;
                this.sname = sname;
            this.sgender = sgender;
            this.phone = phone;
            this.info = info;
            this.birthday = birthday;
        }
    
        public int getSid() {
            return sid;
        }
        public void setSid(int Sid) {
            this.sid = sid;
        }
        public String getSname() {
            return sname;
        }
        public void setSname(String sname) {
            this.sname = sname;
        }
        public String getSgender() {
            return sgender;
        }
        public void setSgender(String sgender) {
            this.sgender = sgender;
        }
        public String getPhone() {
            return phone;
        }
        public void setPhone(String phone) {
            this.phone = phone;
        }
        public String getInfo() {
            return info;
        }
        public void setInfo(String info) {
            this.info = info;
        }
        public Date getBirthday() {
            return birthday;
        }
        public void setBirthday(Date birthday) {
            this.birthday = birthday;
        }
        
    }        
    View Code

      数据库如下:

      原因:student.java中缺少变量,无法完全接受查询到的数据;

      解决方式:添加hoby字段,以及hoby字段的对应的getter和settr方法(构造方法中也要添加该变量);如果javabean声明出错,修改后还是同样的错误,建议重新生成一下(因为我出现了这样的问题)。

      注意:在数据库中create table student( sid int,sname varchar(20) )对应的Student类变量private Int sid; private String sname;其中类型需要一致,同时设置getter和setter方法;

      

    private String hoby;
    
    
    public String getHoby() {
        return hoby;
    }
    
    public void setHoby(String hoby) {
        this.hoby = hoby;
    }
    View Code

    3、java.sql.SQLException: Cannot create StuBean.Student: StuBean.Student Query: select * from stu Parameters: []

      原因:Student.java中缺少无参的构造函数。添加无参构造函数即可。

    欢迎大家补充交流。

  • 相关阅读:
    springboot搭建环境访问Controller层返回404
    SpringMVC使用注解@RequestMapping映射请求
    Redis数据类型
    mysql小结
    将数据四舍五入到十位
    Repeated DNA Sequences
    Reverse Linked List II
    Shortest Palindrome
    Single Number
    Sort Colors
  • 原文地址:https://www.cnblogs.com/ldd525/p/10473266.html
Copyright © 2011-2022 走看看