1.常用解決方法是:將圖片直接保存在項目的某個目錄中,然后將路徑(一般是相對路徑 'images/tuumb1.gif') 存儲進數據庫,這樣數據量小。效率高

2.Servlet中的代碼
1 public class query extends HttpServlet { 2 public void doGet(HttpServletRequest request, HttpServletResponse response) 3 throws ServletException, IOException { 4 request.setCharacterEncoding("UTF-8"); 5 String action = request.getParameter("action"); 6 if ("all".equals(action)) { 7 // 查找所有的 8 queryAll q = new queryAll(); 9 List<pet_shop> list = q.executeAll(); 10 request.getSession().setAttribute("list", list); 11 response.sendRedirect("index.jsp"); 12 } 13 } 14 15 public void doPost(HttpServletRequest request, HttpServletResponse response) 16 throws ServletException, IOException { 17 doGet(request, response); 18 } 19 20 }
3.jsp中的代碼,通過下面的${li.src }" 表達式 ,就可以得到數據庫中圖片的路徑,在頁面進行顯示了
1 <div class="new_products"> 2 <img src="D:\images\thumb1.gif" alt="" /> 3 <div class="new_prod_box"> 4 <a href="query?action=all">點擊點擊點擊點擊點擊</a> 5 <c:forEach var="li" items="${list }"> 6 <a href="#">${li.uname}</a> 7 <a href="#"><img src="${li.src }" /></a> 8 <div class="new_prod_bg"></div> 9 </c:forEach> 10 </div> 11 </div>
