43.web page shows the ticket list is completed briefly
Code:
Control Layer Code
1 PackageCom.day03.station.controller;2 3 ImportCom.day03.station.model.Ticket;4 ImportCom.day03.station.service.impl.TicketService;5 6 Importjavax.servlet.ServletException;7 ImportJavax.servlet.annotation.WebServlet;8 ImportJavax.servlet.http.HttpServlet;9 Importjavax.servlet.http.HttpServletRequest;Ten ImportJavax.servlet.http.HttpServletResponse; One Importjava.io.IOException; A Importjava.util.List; - - /** the * Course notes:http://www.cnblogs.com/newAndHui/category/1153640.html - * Inquiry wx:851298348 - */ -@WebServlet ("/list") + Public classTicketlistservletextendsHttpServlet { - //Business Objects + PrivateTicketservice ticketservice=NewTicketservice (); A /** at * Check Ticket list - * @paramreq - * @paramresp - * @throwsservletexception - * @throwsIOException - */ in @Override - Public voidService (HttpServletRequest req, HttpServletResponse resp)throwsservletexception, IOException { to //1. Receiving Parameters + //2. Calling the Business method -list<ticket> list =Ticketservice.queryall (); theReq.setattribute ("list", list); * //3. Control Jump $Req.getrequestdispatcher ("/web-inf/views/ticketlist.jsp"). Forward (REQ,RESP);Panax Notoginseng - } the}
Ticketlistservlet
JSP code
1<%@ page contenttype= "Text/html;charset=utf-8" language= "java" pageencoding= "UTF-8"%>234<title> Ticket list </title>56<body>7 I am the Ticket list page8 ${list}9<%--Ten Table Labels OneLine <tr> AColumns <td> ---%> -<table align= "Center" border= "1" > the<tr> -<td> numbering </td> -<td>start_station</td> -<td>stop_station</td> +<td>start_time</td> -<td>ticket_price</td> +</tr> A<tr> at<td>${list[0].id}</td> -<td>${list[0].startStation}</td> -<td>${list[0].stopStation}</td> -<td>${list[0].startTime}</td> -<td>${list[0].ticketPrice}</td> -</tr> in<tr> -<td>${list[1].id}</td> to<td>${list[1].startStation}</td> +<td>${list[1].stopStation}</td> -<td>${list[1].startTime}</td> the<td>${list[1].ticketPrice}</td> *</tr> $<tr>Panax Notoginseng<td>${list[2].id}</td> -<td>${list[2].startStation}</td> the<td>${list[2].stopStation}</td> +<td>${list[2].startTime}</td> A<td>${list[2].ticketPrice}</td> the</tr> + -</table> $</body> $ticketlist.jsp44.web page Show ticket list implementation 1. Preparation before using the C tag
To completely eliminate Java code in the JSP, learn the Java tag Library:
Java Tag Library:
Standard Tag Library (JSTL). (Sun pre-provided good, we use.)
When you learn the MVC Framework (STRUTS2/SPRINGMVC) Later, you will learn a set of tags.
=====================================================================
Get ready:
1: Prepare the JSTL related jar (tomcat root/webapps/examples/web-inf/lib).
Jstl.jar Standard.jar
El-api.jar Jsp-api.jar
2: Using Jstl jsp page, inductive tag library:
such as inductive core JSTL:
<%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>
3: Note: Some idea does not add a C tag library, so you must manually add
2.ide Configuration
JSP Code:
1 <%@ Page ContentType="Text/html;charset=utf-8"language="Java"pageencoding="UTF-8" %>2 <%@ taglib URI="Http://java.sun.com/jsp/jstl/core"prefix="C"%>3 <HTML>4 <Head>5 <title>Ticket List</title>6 </Head>7 <Body>8 I am the Ticket list page9 Ten <%-- One Table Labels A Line<TR> - column<TD> - --%> the <TableAlign= "Center"Border= "1"> - <TR> - <TD>Number</TD> - <TD>Start_station</TD> + <TD>Stop_station</TD> - <TD>Start_time</TD> + <TD>Ticket_price</TD> A </TR> at <C:foreachItems= "${list}"var= "Ticket"> - <TR> - <TD>${ticket.id}</TD> - <TD>${ticket.startstation}</TD> - <TD>${ticket.stopstation}</TD> - <TD>${ticket.starttime}</TD> in <TD>${ticket.ticketprice}</TD> - </TR> to </C:foreach> + - </Table> the </Body> * </HTML>
View Code04_web Basic (eight) tickets for the implementation of additions and deletions to check the primary version