前提・実現したいこと
listの値をどのように変数に格納したらいいか教えてください。
以下if文で、bookNameにlist のgetBooktitleを格納したいです。
よろしくお願いいたします。
Serblet
1package book; 2 3import java.io.IOException; 4import java.util.ArrayList; 5 6import javax.servlet.RequestDispatcher; 7import javax.servlet.ServletException; 8import javax.servlet.annotation.WebServlet; 9import javax.servlet.http.HttpServlet; 10import javax.servlet.http.HttpServletRequest; 11import javax.servlet.http.HttpServletResponse; 12 13import dao.BookDao; 14import dba.DBManager; 15import dto.BookDto; 16 17/** 18 * Servlet implementation class BookDetailServlet 19 */ 20@WebServlet(description = "一覧画面にて作品詳細ボタン押下時に受け取るServletクラス", urlPatterns = { "/BookDetailServlet" }) 21public class BookDetailServlet extends HttpServlet { 22 private static final long serialVersionUID = 1L; 23 24 /** 25 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse 26 * response) 27 */ 28 protected void doGet(HttpServletRequest request, HttpServletResponse response) 29 throws ServletException, IOException { 30 31 int id = 0; 32 String bookName = null; 33 String detail = null; 34 String author = null; 35 36 BookDto book = new BookDto(id, bookName, detail, author); 37 String idAsString = request.getParameter("id"); 38 id = Integer.parseInt(idAsString); 39 40 DBManager db = new DBManager(); 41 42 try { 43 BookDao bookDao = new BookDao(db); 44 ArrayList<BookDto> list = bookDao.find(id); 45 46 request.setCharacterEncoding("UTF8"); 47 request.setAttribute("list", list); 48 49 if (list != null) { 50 bookName = *******; 51 detail = *******; 52 author = *******; 53 request.setAttribute("booktitle", bookName); 54 request.setAttribute("text", detail); 55 request.setAttribute("author", author); 56 RequestDispatcher dispatcher = request.getRequestDispatcher("/detail.jsp"); 57 dispatcher.forward(request, response); 58 } 59 } catch (Exception e) { 60 e.printStackTrace(); 61 } 62 } 63 64} 65
回答1件
あなたの回答
tips
プレビュー