前提・実現したいこと
DBの値を使用して、ジャンル検索としてJSPから別のJSPへ遷移させたい。
発生している問題・エラーメッセージ
500エラーがでてしまう
Java
1public class bookgenreDao { 2 3 public static List<booklist> findById(int genreid){ 4 5 6 Connection con=null; 7 PreparedStatement ps=null; 8 9 10 List<booklist> bl=new ArrayList<booklist>(); 11 try{ 12 13 con=DBManager.getConnection(); 14 ps.getConnection().prepareStatement("SELECT * FROM book b INNER JOIN genre g ON b.genre_id = g.genre_id WHERE b.genre_id = ? ORDER BY book_id"); 15 ps.setInt(1, genreid); 16 17 ResultSet rs=ps.executeQuery(); 18 19 while(rs.next()){ 20 booklist book=new booklist(); 21 22 book.setBookid(rs.getInt("book_id")); 23 book.setBookname(rs.getString("book_name")); 24 book.setAuthor(rs.getString("author")); 25 book.setDate(rs.getDate("publication_date")); 26 book.setStock(rs.getInt("stock")); 27 28 Genre genre=new Genre(); 29 genre.setGenreid(rs.getInt("genre_id")); 30 genre.setGenrename(rs.getString("genre_name")); 31 book.setGenre(genre); 32 bl.add(book); 33 } 34 }catch(SQLException e){ 35 e.printStackTrace(); 36 37 }finally{ 38 DBManager.close(ps,con); 39 } 40 return bl; 41 42} 43} 44
<form action="<%=request.getContextPath()%>/selectgenrename" method="Post"> <p>ジャンル名:<select name="book"> <option value="1">文学</option> <option value="2">経済</option> <option value="3">技術</option> </select> <input type="submit" value="検索"/> </form>
<%@ 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=UTF-8"> <link href="<%=request.getContextPath()%>/css/style.css"rel="stylesheet"> </head> <body> <%@include file="/WEB-INF/header.jsp" %> <article class="main"> <h2>書籍一覧</h2> <table> <tr> <th>書籍ID</th> <th>書籍名</th> <th>著者名</th> <th>発行日</th> <th>在庫</th> <th>ジャンル名</th> </tr> <c:forEach var="book" items="${bl}"> <tr> <td>${book.bookid}</td> <td>${book.bookname}</td> <td>${book.author}</td> <td>${book.date}</td> <td>${book.stock}</td> <td>${book.genre.genrename}</td> </tr> </c:forEach> </table> </article> <%@include file="/WEB-INF/footer.jsp" %> </body> </html>
@WebServlet("/selectgenrename") public class selectgenrename extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int book=Integer.parseInt(request.getParameter("book")); List<booklist> bl=bookgenreDao.findById(book); request.setAttribute("bl", bl); request.getRequestDispatcher("/booktable/genreresult.jsp").forward(request,response); } }
初歩的な間違えかもしれないのですが、お手上げ状態なのでご教授いただけたら嬉しいです。
よろしくお願いします。