1. 程式人生 > >Jsp動態網站初步專案 --簡單的商品瀏覽頁面(商品瀏覽頁面index.jsp)

Jsp動態網站初步專案 --簡單的商品瀏覽頁面(商品瀏覽頁面index.jsp)

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@ page import = "com.dao.ItemDAO" %>
<%@ page import = "com.bean.Item" %>
<%
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>
         <!-- 商品迴圈開始 -->
        <% 
             ItemDAO dao = new ItemDAO();
             ArrayList<Item> items = dao.getAllitems();
           //  out.println("商品數目:"+items.size());
             if(items!=null&&items.size()>0)
             {
                for(Item item:items)
                {
        %>
           <div>
             <dl> 
                 <dt> 
                   <a href="details.jsp?id=<%=item.getId() %>"> <img src="image/<%=item.getImage()%>" width="120" height="120"> </a>
                 </dt>
                 <dd class="dd_name">名稱:<%=item.getName() %></dd>
                 <dd class="dd_city"> 產地 :<%=item.getCity() %>   價格:¥<%=item.getPrice() %></dd>
             
             </dl>
           </div>
           <%
                  }
               }
            %>
           <!-- 商品迴圈結束 -->
           
         </td>
       </tr>
       
        
       </table>
     </center>
  </body>
</html>