디비
create table sangpum(
bunho number(5) primary key,
name varchar2(50) NOT NULL,
price number(5) NOT NULL,
defail varchar2(50) NOT NULL,
imagename varchar2(50) NOT NULL
};
select * from sangpum;
select * from sangpum where bunho = 1;
INSERT into sangpum values(4,'이쁜',400,'이쁜','d.gif');
INSERT into sangpum values(5,'멋진',600,'멋진','e.gif');
INSERT into sangpum values(6,'장난',700,'장난','f.gif');
a,b,c,는 좀 넣어줘요.. 1,2,3, 번으로 넣으면 됩니당.
cartlist.jsp
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%
int i = 0;
String bun = "";
String name = "";
String price = "";
String defail = "";
String imagename = "";
Connection conn = null;
Statement ps = null;
ResultSet rs = null;
// 1. 드라이버 로딩
Class.forName("oracle.jdbc.driver.OracleDriver");
// 2. 연결객체 얻어오기
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
// 3. sql 문장 만들기
String sql = "select * from sangpum ";
// 4. sql 전송객체 얻어오기
ps = conn.createStatement();
// 5. 전송
rs = ps.executeQuery(sql);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table>
<%
while (rs.next()) {
bun = rs.getString("bunho");
name = rs.getString("name");
price = rs.getString("price");
defail = rs.getString("defail");
imagename = rs.getString("imagename");
if (i < 3) {
%>
<td><a href = "cartDetail.jsp?bunho=<%=bun%>"><img src="img/<%=imagename%>" width="300" height="300" ></a>
<br /><h4 align="center"> 상품명 : <%=name%> </h4></td>
<%
i++;
} else {
i = 0;
%>
<tr>
<td><a href = "cartDetail.jsp?bunho=<%=bun%>"><img src="img/<%=imagename%>" width="300" height="300" ></a>
<br /><h4 align="center"> 상품명 : <%=name%> </h4></td>
<%
i++;
}
}
%>
</table>
</body>
</html>
cartdetail.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%
String bunho = "";
String bun = "";
String name = "";
String price = "";
String defail = "";
String imagename = "";
Vector glist = null;
request.setCharacterEncoding("utf-8");
bunho = request.getParameter("bunho");
Connection conn = null;
Statement ps = null;
ResultSet rs = null;
// 1. 드라이버 로딩
Class.forName("oracle.jdbc.driver.OracleDriver");
// 2. 연결객체 얻어오기
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
// 3. sql 문장 만들기
String sql = "select * from sangpum where bunho = '" + bunho + "' ";
// 4. sql 전송객체 얻어오기
ps = conn.createStatement();
// 5. 전송
rs = ps.executeQuery(sql);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
while (rs.next()) {
bun = rs.getString("bunho");
name = rs.getString("name");
price = rs.getString("price");
defail = rs.getString("defail");
imagename = rs.getString("imagename");
}
%>
품번 : <%=bun%> <BR/>
상품명 : <%=name%> <BR/>
가격 : <%=price%> <BR/>
설명 : <%=defail%> <BR/>
이미지:<img src="img/<%=imagename%>" width="300" height="300" >
<form action='cart.jsp' method='post'>
<input type='hidden' name='bunho' value=<%=bun%>>
<input type='hidden' name='name' value=<%=name%>>
<input type='hidden' name='price' value=<%=price%>>
<input type='submit' value="장바구니">
</body>
</html>
cart.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.util.*" %>
<%@ page import="shop.cart.Goods1" %>
<%
String bunho="";
String name ="";
int price=0;
Vector glist = null;
request.setCharacterEncoding("EUC-KR");
bunho = request.getParameter("bunho");
name = request.getParameter("name");
String priceTemp = request.getParameter("price");
if(priceTemp != null){
price = Integer.parseInt(priceTemp);
}
Object listObj = session.getAttribute("list");
if(listObj == null){
glist = new Vector();
}else{
glist = (Vector)listObj;
}
Goods1 g = new Goods1(bunho,name,price);
glist.addElement(g);
session.setAttribute("list", glist);
%>
<html>
<body bgcolor=white>
<%= name %> 을 구입하셨습니다.
<br><br><br>
<table width=100%>
<tr bgcolor=#e7a068><th>상품명</th>
<th>가격</th></tr>
<%
int n = glist.size();
int sum = 0;
for(int i=0; i < n; i++) {
Goods1 goods = (Goods1) glist.elementAt(i);
int gp = goods.getPrice();
sum += gp;
%>
<tr><td align=center> <%= goods.getName() %> </td>
<td align=right> <%= gp %> </td></tr>
<%
}
%>
<tr bgcolor=#e7a068><td colspan=2 align=right> 총액 : <%= sum %></td></tr>
</table>
<br><br><center>
[<a href=wshop.html>쇼핑하러 가기</a>]
[<a href=Buy.jsp>구입하기</a>]
</body></html>
Goods1.java
package shop.cart;
public class Goods1 {
private String bunho;
private String name;
private int price;
public Goods1(String bunho, String name, int price) {
this.bunho = bunho;
this.name = name;
this.price = price;
}
public void setPrice(int price) {
this.price = price;
}
public String getbunho() {
return bunho;
}
public String getName() {
return name;
}
public int getPrice() {
return price;
}
}
'it > JSP' 카테고리의 다른 글
게시판. bean, javascript 이용 게시판 갯수 등등작업 완료 (0) | 2014.08.26 |
---|---|
회원가입 Bean, 자바스크립트,jdbc 이용 (0) | 2014.08.26 |
팝업창 (0) | 2014.08.25 |
크롬 캐시 폴더 확인. (0) | 2014.08.25 |
publishing to tomcat v7.0 server at localhost...' has encountered a problem (0) | 2014.08.25 |