一 代码
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@ page import="entity.Items"%>
<%@ page import="dao.ItemsDAO"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'index.jsp' starting page</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">   
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
        <style type="text/css">
           div{
              float:left;
              margin: 10px;
           }
           div dd{
              margin:0px;
              font-size:10pt;
           }
           div dd.dd_name
           {
              color:blue;
           }
           div dd.dd_city
           {
              color:#000;
           }
        </style>
  </head>
 
  <body>
    <h1>商品展示</h1>
    <hr>
 
    <center>
    <table width="750" height="60" cellpadding="0" cellspacing="0" border="0">
      <tr>
        <td>
         
          <!-- 商品循环开始 -->
           <%
               ItemsDAO itemsDao = new ItemsDAO();
               ArrayList<Items> list = itemsDao.getAllItems();
               if(list!=null&&list.size()>0)
               {
                       for(int i=0;i<list.size();i++)
                       {
                          Items item = list.get(i);
           %>  
          <div>
             <dl>
               <dt>
                 <a href="details.jsp?id=<%=item.getId()%>"><img src="images/<%=item.getPicture()%>" width="120" height="90" border="1"/></a>
               </dt>
               <dd class="dd_name"><%=item.getName() %></dd>
               <dd class="dd_city">产地:<%=item.getCity() %>&nbsp;&nbsp;价格:¥ <%=item.getPrice() %></dd>
             </dl>
          </div>
          <!-- 商品循环结束 -->
       
          <%
                   }
              }
          %>
        </td>
      </tr>
    </table>
    </center>
  </body>
</html>
 
二 测试

商品浏览系统之首页
 

相关文章:

  • 2021-11-27
  • 2022-02-09
  • 2021-11-12
  • 2021-07-29
  • 2022-01-20
  • 2021-10-20
  • 2021-09-28
  • 2021-12-22
猜你喜欢
  • 2021-11-13
  • 2022-12-23
  • 2021-12-04
  • 2022-02-26
  • 2021-07-10
  • 2021-08-19
  • 2023-04-02
相关资源
相似解决方案