12.8 JSP页面
/MyBookApp/WebContent/WEB-INF/jsp/loginForm.jsp1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>登录页面</title> </head> <body> <h3>登录页面</h3> <form action="login" method="post"> <font color="red">${requestScope.message }</font> <table> <tr> <td><label>登录名: </label></td> <td><input type="text" id="loginname" name="loginname"></td> </tr> <tr> <td><label>密码: </label></td> <td><input type="password" id="password" name="password"></td> </tr> <tr> <td><input type="submit" value="登录"></td> </tr> </table> </form> </body> </html>
|
main.jsp
/MyBookApp/WebContent/WEB-INF/jsp/main.jsp1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>书籍列表</title> <style type="text/css"> table { border-collapse: collapse; border-spacing: 0; border-left: 1px solid #888; border-top: 1px solid #888; background: #efefef; }
th, td { border-right: 1px solid #888; border-bottom: 1px solid #888; padding: 5px 15px; }
th { font-weight: bold; background: #ccc; } </style> </head> <body> <span>欢迎[${sessionScope.user.username}]访问.</span> <table> <tr> <th>封面</th> <th>书名</th> <th>作者</th> <th>价格</th> </tr> <tr> <c:forEach items="${requestScope.book_list}" var="book"> <td><img alt="此处有一张图片" src="${book.image}" height="60"></td> <td>${book.name}</td> <td>${book.author}</td> <td>${book.price}</td> </c:forEach> </tr> </table> </body> </html>
|
loginForm.jsp
是一个登录页面,可以在此输入登录名和密码进行登录。登录完成后main.jsp
显示从数据库tb_book
表读取出的书籍信息。