webapp中的异常,即org.apache.jasper.JasperException

时间:2018-09-05 03:13:17

标签: java spring eclipse spring-mvc derby

我建立了一个dao层,该层使用jdbctemplate与derby db连接。

insert查询工作正常,但是当我尝试从数据库中选择所有行时,webapp给我这个错误:

  

org.apache.jasper.JasperException:处理过程中发生异常   第26行的JSP页面/WEB-INF/jsp/DisplayEmployee.jsp

     

23:24:25:26:$ {temp.FirstName} 27:   $ {temp.MiddleName} 28:$ {temp.LastName}   29:$ {temp.email}

     

avax.el.PropertyNotFoundException:在上找不到属性“ FirstName”   键入com.user.EmployeeInfo

enter image description here

代码:

DAO:

public class EmployeeDao {
    JdbcTemplate template;  
    public void setTemplate(JdbcTemplate template) {  
        this.template = template;  
    }  
    public int insert(EmployeeInfo emp){

        String sql = "insert into employee VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
        int i=template.update(sql, emp.getFirstName(), emp.getMiddleName(), emp.getLastName(), emp.getEmail(), emp.getGender(), emp.getDob(), emp.getAddress1(), emp.getAddress2(), emp.getEmpID());
        return i;
    }

    public List<EmployeeInfo> retrieveMultipleRowsColumns(){
        String sql = "select * from employee";
        //return template.queryForList(sql, elementType)
        //List<EmployeeInfo> list = template.query(sql,new BeanPropertyRowMapper<EmployeeInfo>(EmployeeInfo.class));
        //List<EmployeeInfo> list2 = template.queryForList(sql, EmployeeInfo.class);
        List<EmployeeInfo> list3 = template.query(sql, new RowMapper<EmployeeInfo>(){ 
                public EmployeeInfo mapRow(ResultSet rs, int rownumber) throws SQLException {  
                    EmployeeInfo e = new EmployeeInfo();
                    e.setFirstName(rs.getString(1));
                    e.setMiddleName(rs.getString(2));
                    e.setLastName(rs.getString(3));
                    e.setEmail(rs.getString(4));
                    e.setGender(rs.getString(5));
                    e.setDob(rs.getDate(6));
                    e.setAddress1(rs.getString(7));
                    e.setAddress2(rs.getString(8));
                    e.setEmpID(rs.getInt(9));
                    return e;  
                }  
        });
        return list3;
    }

控制器:

public class EmployeeAddition {  
    @Autowired  
    EmployeeDao dao;
    @RequestMapping("/addresult")  
    public ModelAndView addResult(HttpServletRequest req,HttpServletResponse res) {

        String fname = req.getParameter("FirstName");
        String mname = req.getParameter("MiddleName");
        String middlename;
        if(mname!="null"&&mname.trim()!=""){
            middlename=mname;
        }
        else
        {
            middlename="-";
        }
        String lname = req.getParameter("LastName");
        String empid = req.getParameter("empID");
        int empID = Integer.parseInt(empid);
        String email = req.getParameter("Email");
        String gender = req.getParameter("gender");
        Date dob = Date.valueOf(req.getParameter("DOB"));
        String addr1 = req.getParameter("address1");
        String addr2 = req.getParameter("address2");
        EmployeeInfo emp = new EmployeeInfo(fname,middlename,lname,email,gender,dob,addr1,addr2,empID);
        int ret = dao.insert(emp);

        if(ret==0){
            return new ModelAndView("EmployeeAddResult","mess","Success");
        }
        else
        {
        return new ModelAndView("EmployeeAddResult","mess","hi");
        }
    }    
    @RequestMapping("/display")  
    public ModelAndView viewEmployee(HttpServletRequest req,HttpServletResponse res,ModelMap model) {
        List<EmployeeInfo> list=dao.retrieveMultipleRowsColumns();
        model.put("list",list);
        return new ModelAndView("DisplayEmployee","mess","Welcome "+(String)req.getSession().getAttribute("uname"));
    } 
}  

我要在其中显示结果的jsp:

<div class="right_disp left">
        <c:forEach items="${list}" var="temp">
            <tr>
            <td>${temp.FirstName}</td>
            <td>${temp.MiddleName}</td>
            <td>${temp.LastName}</td>
            <td>${temp.email}</td>
            <td>${temp.gender}</td>
            <td>${temp.dob}</td>
            <td>${temp.Address1}</td>
            <td>${temp.Address2}</td>
            <td>${temp.empID}</td>
            </tr>
        </c:forEach>
    </div>

变量名称与POJO类的原始变量匹配,但我不明白为什么在类上找不到Property的错误。

感谢任何建议或帮助。

编辑:

EmployeeInfo类(POJO)

import java.sql.Date;

public class EmployeeInfo {
    String FirstName;
    String MiddleName;
    String LastName;
    String email;
    String gender;
    Date dob;   
    String Address1;
    String Address2;
    int empID;

    public EmployeeInfo(){

    }

    public EmployeeInfo(String firstName, String middleName, String lastName, String email, String gender,
            Date dob, String address1, String address2, int empID) {
        super();
        FirstName = firstName;
        MiddleName = middleName;
        LastName = lastName;
        this.email = email;
        this.gender = gender;
        this.dob = dob;
        Address1 = address1;
        Address2 = address2;
        this.empID = empID;
    }

    public String getFirstName() {
        return FirstName;
    }
    public void setFirstName(String firstName) {
        FirstName = firstName;
    }
    public String getMiddleName() {
        return MiddleName;
    }
    public void setMiddleName(String middleName) {
        MiddleName = middleName;
    }
    public String getLastName() {
        return LastName;
    }
    public void setLastName(String lastName) {
        LastName = lastName;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getGender() {
        return gender;
    }
    public void setGender(String gender) {
        this.gender = gender;
    }
    public Date getDob() {
        return dob;
    }
    public void setDob(Date dob) {
        this.dob = dob;
    }
    public String getAddress1() {
        return Address1;
    }
    public void setAddress1(String address1) {
        Address1 = address1;
    }
    public String getAddress2() {
        return Address2;
    }
    public void setAddress2(String address2) {
        Address2 = address2;
    }
    public int getEmpID() {
        return empID;
    }
    public void setEmpID(int empID) {
        this.empID = empID;
    }

}

2 个答案:

答案 0 :(得分:2)

如果属性名称遵循Bean属性命名约定,则不要将其首字母大写。

如果您的getter和setter分别命名为getSomePropertysetSomeProperty,则在模板中应使用someProperty而不是SomeProperty

答案 1 :(得分:1)

您的命名约定就是问题。尝试全面遵守一些惯例(例如:骆驼肠衣)

<td>${temp.FirstName}</td>

尝试更新为

<td>${temp.firstName}</td>