データベースのデータをarrayListを用いてjspに表示したい。
これを実装すると${emp.empId}が読込めていない旨のエラーが表示されます。
- エラー
type 例外レポート メッセージ An exception occurred processing JSP page /html/list/list.jsp at line 61 説明 The server encountered an internal error that prevented it from fulfilling this request. 例外 org.apache.jasper.JasperException: An exception occurred processing JSP page /html/list/list.jsp at line 61 58: </tr> 59: <c:forEach var="emp" items="${empList} "> 60: <tr> 61: <td>${emp.empId}</td> 62: <td>${emp.empName}</td> 63: <td>${emp.gender}</td> 64: <td>${emp.address}</td> Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:574) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) jp.co.sss.crud.servlet.SelectAll.doGet(SelectAll.java:23) javax.servlet.http.HttpServlet.service(HttpServlet.java:622) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 原因 javax.el.PropertyNotFoundException: Property 'empId' not found on type java.lang.String javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:268) javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:221) javax.el.BeanELResolver.property(BeanELResolver.java:355) javax.el.BeanELResolver.getValue(BeanELResolver.java:95) org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110) org.apache.el.parser.AstValue.getValue(AstValue.java:169) org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:943) org.apache.jsp.html.list.list_jsp._jspService(list_jsp.java:197) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) jp.co.sss.crud.servlet.SelectAll.doGet(SelectAll.java:23) javax.servlet.http.HttpServlet.service(HttpServlet.java:622) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Emp
1package jp.co.sss.crud.bean; 2 3import java.util.Date; 4 5public class Emp { 6 private int empId; 7 private String empPass; 8 private String empName; 9 private int gender; 10 private String address; 11 private Date birthday; 12 private int authority; 13 private Dept dept; 14 15 public int getEmpId() { 16 return empId; 17 } 18 public void setEmpId(int empId) { 19 this.empId = empId; 20 } 21 public String getEmpPass() { 22 return empPass; 23 } 24 public void setEmpPass(String empPass) { 25 this.empPass = empPass; 26 } 27 public String getEmpName() { 28 return empName; 29 } 30 public void setEmpName(String empName) { 31 this.empName = empName; 32 } 33 public int getGender() { 34 return gender; 35 } 36 public void setGender(int gender) { 37 this.gender = gender; 38 } 39 public String getAddress() { 40 return address; 41 } 42 public void setAddress(String address) { 43 this.address = address; 44 } 45 public Date getBirthday() { 46 return birthday; 47 } 48 public void setBirthday(Date birthday) { 49 this.birthday = birthday; 50 } 51 public int getAuthority() { 52 return authority; 53 } 54 public void setAuthority(int authority) { 55 this.authority = authority; 56 } 57 public Dept getDept() { 58 return dept; 59 } 60 public void setDept(Dept dept) { 61 this.dept = dept; 62 } 63 64}
jsp
1<%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 4<!DOCTYPE html> 5<html> 6<head> 7<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 8<link rel="stylesheet" href="../../css/layout.css" /> 9<link rel="stylesheet" href="../../css/style.css" /> 10<title>社員管理システム</title> 11</head> 12<body class="list"> 13 <header> 14 <div class="content"> 15 <div class="title">社員管理システム</div> 16 <div class="user_info">ようこそ、<a href="../update/update_input.jsp">田中二郎</a>さん<span class="pipeline">|</span><a href="../index.jsp">ログアウト</a> 17 </div> 18 </div> 19 </header> 20 21 <div class="container content"> 22 <aside class="search"> 23 <div class="title">社員名検索</div> 24 <div class="form"> 25 <form action="<%=request.getContextPath() %>/SelectName" method="post"> 26 <input type="text" name="empName" /> 27 <input type="submit" value="検索" /> 28 </form> 29 </div> 30 <div class="title">部署名検索</div> 31 <div class="form"> 32 <form action="list.jsp"> 33 <select name="deptId"> 34 <option value="1" selected="selected">営業部</option> 35 <option value="2">経理部</option> 36 <option value="3">総務部</option> 37 </select> 38 <input type="submit" value="検索" /> 39 </form> 40 </div> 41 </aside> 42 43 <article class="main"> 44 <h3 class="page_title">社員一覧画面</h3> 45 <div class="regist_link"> 46 <a href="../regist/regist_input.jsp">新規社員登録</a> 47 </div> 48 <table class="emp_list_table"> 49 <tr> 50 <th class="empId">社員ID</th> 51 <th class="empName">社員名</th> 52 <th class="gender">性別</th> 53 <th class="address">住所</th> 54 <th class="birthday">生年月日</th> 55 <th class="authority">権限</th> 56 <th class="deptName">部署名</th> 57 <th class="button" colspan="2">操作</th> 58 </tr> 59 <c:forEach var="emp" items="${empList} "> 60 <tr> 61 <td>${emp.empId}</td> 62 <td>${emp.empName}</td> 63 <td>${emp.gender}</td> 64 <td>${emp.address}</td> 65 <td>${emp.birthday}</td> 66 <td>${emp.authority}</td> 67 <td>${emp.dept.deptName}</td> 68 <td class="button"> 69 <form action="../update/update_input.jsp"> 70 <input type="hidden" name="${emp.empId}"/> 71 <input type="submit" value="変更" /> 72 </form> 73 </td> 74 <td class="button"> 75 <form action="<%=request.getContextPath() %>/DeleteCheck"> 76 <input type="hidden" name="${emp.empId }"/> 77 <input type="submit" value="削除" class="delete" /> 78 </form> 79 </td> 80 </tr> 81 </c:forEach> 82 </table> 83 </article> 84 </div> 85 86 <footer> 87 <small>Copyright(C) 2017 System Shared co., ltd, ALL Rights Reserved</small> 88 <!-- small要素は免責・著作権・ライセンス要件などを表す際に使用します。 --> 89 </footer> 90</body> 91</html>
servlet
1package jp.co.sss.crud.servlet; 2 3import java.io.IOException; 4import java.util.List; 5 6import javax.servlet.ServletException; 7import javax.servlet.annotation.WebServlet; 8import javax.servlet.http.HttpServlet; 9import javax.servlet.http.HttpServletRequest; 10import javax.servlet.http.HttpServletResponse; 11 12import jp.co.sss.crud.bean.Emp; 13import jp.co.sss.crud.db.EmpDao; 14 15/** 16 * Servlet implementation class SelectAll 17 */ 18@WebServlet("/SelectAll") 19public class SelectAll extends HttpServlet { 20 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 21 List<Emp> empList =EmpDao.findAll(); 22 request.setAttribute("empList", empList); 23 request.getRequestDispatcher("/html/list/list.jsp").forward(request, response); 24 } 25} 26
EmpDao
1public class EmpDao { 2 public static List<Emp> findAll() { 3 4 Connection con = null; 5 PreparedStatement ps = null; 6 7 List<Emp> empList = new ArrayList<Emp>(); 8 9 try { 10 con = DBManager.getConnection(); 11 ps = con.prepareStatement("SELECT e.emp_id, e.emp_name, e.gender, e.address, e.birthday, e.authority, d.dept_name FROM employee e INNER JOIN department d ON e.dept_id = d.dept_id"); 12 ResultSet rs = ps.executeQuery(); 13 14 while (rs.next()) { 15 16 Emp emp = new Emp(); 17 emp.setEmpId(rs.getInt("emp_id")); 18 emp.setEmpName(rs.getString("emp_name")); 19 emp.setGender(rs.getInt("gender")); 20 emp.setAddress(rs.getString("address")); 21 emp.setBirthday(rs.getDate("birthday")); 22 emp.setAuthority(rs.getInt("authority")); 23 24 Dept dept = new Dept(); 25 dept.setDeptName(rs.getString("dept_name")); 26 empList.add(emp); 27 } 28 } catch (SQLException e) { 29 e.printStackTrace(); 30 } finally { 31 DBManager.close(ps, con); 32 } 33 return empList; 34 }
回答4件
あなたの回答
tips
プレビュー