获得商品详情的时候,总是报错。The method getItemsById(int) is undefined for the type ItemsDAO

来源:8-7 商品详细信息显示

旧时光__

2017-10-25 17:05


<%@ 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 'detail.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">

img {

border: 1px solid black;

height: 140px;

width: 180px;

}

</style>

</head>


<body>

<h1>商品详情</h1>

<hr>

<center>

<table width="750" height="60" cellpadding="0" cellspacing="0"

border="0">

<tr>

<td>

<%

ItemsDAO itemsDao = new ItemsDAO();

Items item = itemsDao.getItemsById(Integer.parseInt(request.getParameter("id")));

if(item != null)

{

%>

<table>

<tr>

<td rowspan="4"><img alt="运动鞋" src="images/<%=item.getPicture() %>"></td>

</tr>

<tr>

<td><big><%=item.getName() %></big></td>

</tr>

<tr>

<td>产地:<%=item.getCity() %></td>

</tr>

<tr>

<td>价格:<%=item.getPrice() %></td>

</tr>

</table>

<%

}

%>

</td>

</tr>

</table>

</center>

</body>

</html>


写回答 关注

2回答

  • 旧时光__
    2017-10-25 17:07:08
    <%@ page language="java" import="java.util.*"
    	contentType="text/html; charset=utf-8"%>
    <%@ page import="entity.Items"%>
    <%@ page import="dao.*"%>
    <%
    	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">
    img {
    	width: 200px;
    	height: 150px;
    	border: 1px solid black;
    }
    
    div {
    	float: left;
    	margin: 10px;
    }
    </style>
    </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>
    					<table>
    						<tr>
    							<td colspan="2"><a href="detail.jsp?id=<%=item.getId()%>"><img alt=""
    									src="images/<%=item.getPicture()%>"></a></td>
    						</tr>
    						<tr>
    							<td><%=item.getName()%></td>
    						</tr>
    						<tr>
    							<td>产地:<%=item.getCity()%></td>
    							<td>价格:<%=item.getPrice()%>元
    							</td>
    						</tr>
    					</table>
    					</div>
    					 <%
     	}
     	}
     %>
    
    				</td>
    			</tr>
    		</table>
    	</center>
    </body>
    </html>


  • 旧时光__
    2017-10-25 17:06:12
    <%@ 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 'detail.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">
    img {
    	border: 1px solid black;
    	height: 140px;
    	width: 180px;
    }
    </style>
    </head>
    
    <body>
    	<h1>商品详情</h1>
    	<hr>
    	<center>
    		<table width="750" height="60" cellpadding="0" cellspacing="0"
    			border="0">
    			<tr>
    				<td>
    					<%
    						ItemsDAO itemsDao = new ItemsDAO();
    						Items item = itemsDao.getItemsById(Integer.parseInt(request.getParameter("id")));
    						if(item != null)
    						{
    					 %>
    					<table>
    						<tr>
    							<td rowspan="4"><img alt="运动鞋" src="images/<%=item.getPicture() %>"></td>
    						</tr>
    						<tr>
    							<td><big><%=item.getName() %></big></td>
    						</tr>
    						<tr>
    							<td>产地:<%=item.getCity() %></td>
    						</tr>
    						<tr>
    							<td>价格:<%=item.getPrice() %></td>
    						</tr>
    					</table>
    					<%
    						}
    					 %>
    				</td>
    				
    			</tr>
    		</table>
    	</center>
    </body>
    </html>


JAVA遇见HTML——JSP篇

Java Web入门级教程JSP,带你轻松的学习JSP基础知识

248277 学习 · 3071 问题

查看课程

相似问题