-
在JSP页面中定义变量或者方法:JSP声明查看全部
-
在JSP页面中执行的java代码:JSP脚本查看全部
-
Jsp注释:只有<!--html注释-->客户端可见查看全部
-
page指令语法查看全部
-
JSP指令查看全部
-
JSP页面组成部分查看全部
-
JSP简介查看全部
-
/*details.jsp③*/ <!-- 浏览过的商品 --> <td width="30%" bgcolor="#eee" align="center"> <br> <b>您浏览过的商品</b><br> <% ArrayList<Items> itemlist = itemsDao.getViewList(list); if(itemlist!=null && itemlist.size()>0){ for(Items i:itemlist){ %> <div> <dl> <dt> <a href="details.jsp?id=<%=i.getId()%>"><img width="120" height="90" border="1" src="images/<%=i.getPicture()%>"></a> </dt> <dd class="dd_name"><%=i.getName()%></dd> <dd class="dd_city">产地:<%=i.getCity()%> 价格:<%=i.getPrice()%></dd> </dl> </div> <% } } %> </td> </tr> </table> </body> </html>查看全部
-
/*details.jsp②*/ <tr> <td>产地:<%=item.getCity() %></td> </tr> <tr> <td>价格<%=item.getPrice() %></td> </tr> </table> </td> <% }%> <% String list = ""; Cookie[] cookies = request.getCookies(); if(cookies!=null&&cookies.length>0){ for(Cookie c:cookies){ if(c.getName().equals("ListViewCookie")){ list = c.getValue(); } } } //若记录数超过1000清零 String[] arr = list.split(","); if(arr!=null && arr.length>0) if(arr.length>1000) list=""; list+=request.getParameter("id")+","; Cookie cookie = new Cookie("ListViewCookie",list); response.addCookie(cookie); %>查看全部
-
/*details.jsp①*/ <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="dao.ItemsDAO" %> <%@ page import="entity.Items" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <style type="text/css"> div{float:left;margin-left:30px;margin-right:5px;margin-bottom:5px;} div dd{margin:0px;font-size:10pt;} div dd .dd_name{color:#blue;} </style> </head> <body> <table width="750" height="60" cellpadding="0" cellspacing="0" border="0"> <tr> <% ItemsDAO itemsDao = new ItemsDAO(); Items item = itemsDao.getItemsById(Integer.parseInt(request.getParameter("id"))); if(item!=null){ %> <!-- 商品详情 --> <td width="70%" valign="top"> <table> <tr> <td rowspan="4"><img width="200" height="160" src="images/<%=item.getPicture()%>"></td> </tr> <tr> <td><b><%=item.getName() %></b></td> </tr>查看全部
-
/*index.jsp②*/ <div> <dl> <dt> <a href="details.jsp?id=<%=item.getId()%>"><img width="120" height="90" border="1" src="images/<%=item.getPicture()%>"></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>查看全部
-
/*index.jsp①*/ <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="dao.ItemsDAO" %> <%@ page import="entity.Items" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <style type="text/css"> div{float:left;margin-left:30px;margin-right:5px;margin-bottom:5px;} div dd{margin:0px;font-size:10pt;} div dd .dd_name{color:#blue;} </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(Items item:list) { %>查看全部
-
/*ItemsDAO类③*/ } catch (Exception e) { e.printStackTrace(); return null; } finally{ if(rs!=null){ rs.close(); rs=null; } if(stmt!=null){ stmt.close(); stmt=null; } } } //获取最近浏览的5条记录 public ArrayList<Items> getViewList(String list) throws SQLException{ ArrayList<Items> itemlist = new ArrayList<Items>(); int iCount = 5; if(list!=null && list.length()>0){ String[] arr = list.split(","); //如果商品记录大于5 if(arr.length>5){ for(int i=arr.length-1;i>=arr.length-iCount;i--){ itemlist.add(getItemsById(Integer.parseInt(arr[i]))); } }else{ for(int i=arr.length-1;i>=0;i--){ itemlist.add(getItemsById(Integer.parseInt(arr[i]))); } } return itemlist; }else{ return null; } } }查看全部
-
/*ItemsDAO类②*/ } catch (Exception e) { e.printStackTrace(); return null; } finally{ if(rs!=null){ rs.close(); rs=null; } if(stmt!=null){ stmt.close(); stmt=null; } } } //根据商品编号获得商品资料 public Items getItemsById(int id) throws SQLException{ Connection conn =null; PreparedStatement stmt = null; ResultSet rs = null; try { conn = DBHelper.getConnection(); String sql = "select * from items where id=?;"; stmt = conn.prepareStatement(sql); stmt.setInt(1, id); rs = stmt.executeQuery(); if(rs.next()){ Items item = new Items(); item.setId(rs.getInt("id")); item.setName(rs.getString("name")); item.setCity(rs.getString("city")); item.setNumber(rs.getInt("number")); item.setPrice(rs.getInt("price")); item.setPicture(rs.getString("picture")); return item; }else{ return null; }查看全部
-
/*ItemsDAO类①*/ package dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import util.DBHelper; import entity.Items; //商品业务逻辑类 public class ItemsDAO { public ArrayList<Items> getAllItems() throws SQLException{ Connection conn =null; PreparedStatement stmt = null; ResultSet rs = null; ArrayList<Items> list = new ArrayList<Items>(); try { conn = DBHelper.getConnection(); String sql = "select * from items;"; stmt = conn.prepareStatement(sql); rs = stmt.executeQuery(); while(rs.next()){ Items item = new Items(); item.setId(rs.getInt("id")); item.setName(rs.getString("name")); item.setCity(rs.getString("city")); item.setNumber(rs.getInt("number")); item.setPrice(rs.getInt("price")); item.setPicture(rs.getString("picture")); list.add(item); } return list;查看全部
举报
0/150
提交
取消