MVC 2 4 Controller n n Model View

  • Slides: 13
Download presentation

MVCモデル 2 (4) Controller n n Model と View を制 御する Servletを使う 7

MVCモデル 2 (4) Controller n n Model と View を制 御する Servletを使う 7

Servlet の処理 // データベースから検索して、結果をBeanに格納 List list = search(ndc, tyosya_hyouji, id, title, author, publisher); //

Servlet の処理 // データベースから検索して、結果をBeanに格納 List list = search(ndc, tyosya_hyouji, id, title, author, publisher); // Http. Session を取り出し、Beanを登録 Http. Session session = request. get. Session(); session. set. Attribute("book. List", list); // 後の処理をJSPに任せる context. get. Request. Dispatcher(jsp. File). forward(request, response); 11

JSP の処理 // タグライブラリの利用を宣言 <%@ taglib prefix="c" uri="http: //java. sun. com/jsp/jstl/core" %> // Http.

JSP の処理 // タグライブラリの利用を宣言 <%@ taglib prefix="c" uri="http: //java. sun. com/jsp/jstl/core" %> // Http. Session から Model であるコレクションを // 取り出す <c: for. Each var="book" items="${session. Scope. book. List}" > 12

タグライブラリを使った ループ処理 <ul> <c: for. Each var="book“ items="${session. Scope. book. List}" > <li> <c:

タグライブラリを使った ループ処理 <ul> <c: for. Each var="book“ items="${session. Scope. book. List}" > <li> <c: out value="${book. title}" /> / <c: out value="${book. author}" /> </li> </c: for. Each> </ul> 13