You are on page 1of 27

INDEX.

JSP
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Mobile Store</title> <link rel="stylesheet" type="text/css" href="style.css" /> <script type="text/javascript" src="js/boxOver.js"></script> </head> <body> <%@ include file="header.jsp" %> <div id="main_container"> <%@ include file="left_menu.jsp" %> <div class="center_content"> <div class="center_title_bar">Special Products</div> <jsp:useBean id="s1" class="beans.Display" scope="page"/> <% List<Object> list=new ArrayList<Object>(); list=s1.displayData("select prodid, prodtitle, price, photo from product where prodid in (select prodid from special)"); for(int i=0; i<list.size();i++) { List<Object> crow=new ArrayList<Object>(); crow=(List)list.get(i); %> <div class="prod_box">

<div class="top_prod_box"></div> <div class="center_prod_box"> <div class="product_title"><a href="productdetail.jsp?prodid=<%=crow.get(0)%>">< %=crow.get(1)%></a></div> <div class="product_img"><a href="productdetail.jsp?prodid=< %=crow.get(0)%>"><img src="images/<%=crow.get(3) %>" alt="" title="" border="0" /></a></div> <div class="product_img"><a href="addcart.jsp?prodid=< %=crow.get(0)%>"><img src="images/addcart.png" alt="" width="100" height="31" border="0" title="" /></a></div> <div class="prod_price"><span class="price">INR <%=crow.get(2)%></span></div> </div> <div class="bottom_prod_box"></div>

</div> <%} %> </div> <%@ include file="right_menu.jsp" %> <%@ include file="footer.jsp" %> </div> </body> </html>

PRODUCTS.JSP
<body> <%@ include file="header.jsp" %> <div id="main_container"> <%@ include file="left_menu.jsp" %>

<div class="center_content"> <div class="center_title_bar">Products</div> <jsp:useBean id="s1" class="beans.Display" scope="page"/> <% String catid, scatid; catid=request.getParameter("catid"); scatid=request.getParameter("scatid"); List<Object> list=new ArrayList<Object>(); if(catid==null) { if(scatid==null) { list=s1.displayData("select prodid, prodtitle, price, photo from product order by prodid desc"); } else { list=s1.displayData("select prodid, prodtitle, price, photo from product where scatid=" + scatid + " order by prodid desc"); } } else { list=s1.displayData("select prodid, prodtitle, price, photo from product where catid=" + catid + " order by prodid desc"); }

for(int i=0; i<list.size();i++) { List<Object> crow=new ArrayList<Object>(); crow=(List)list.get(i); %> <div class="prod_box"> <div class="top_prod_box"></div> <div class="center_prod_box"> <div class="product_title"><a href="productdetail.jsp?prodid=<%=crow.get(0)%>">< %=crow.get(1)%></a></div> <div class="product_img"><a href="productdetail.jsp?prodid=< %=crow.get(0)%>"><img width="90" height="92" src="images/<%=crow.get(3) %>" alt="" title="" border="0" /></a></div> <div class="product_img"><a href="addcart.jsp?prodid=< %=crow.get(0)%>"><img src="images/addcart.png" alt="" width="100" height="31" border="0" title="" /></a></div> <div class="prod_price"><span class="price">INR <%=crow.get(2)%></span></div> </div> <div class="bottom_prod_box"></div>

</div> <%} %> </div> <%@ include file="right_menu.jsp" %> <%@ include file="footer.jsp" %> </div> </body>

MYACCOUNT.JSP
<body> <%@ include file="header.jsp" %> <div id="main_container"> <%@ include file="members_left_menu.jsp" %> <% if(v_custid!=null) { %> <jsp:useBean id="s1" class="beans.Customer" scope="page" /> <% s1.setCustid(Integer.parseInt(v_custid)); boolean found=s1.findRecord(); %> <div class="center_content"> <div class="center_title_bar">My Account </div> <div class="prod_box_big"> <div class="top_prod_box_big"></div> <div class="center_prod_box_big"> <div class="contact_form">

<div class="form_row"> <label class="contact"><strong>Customer ID:</strong></label> <label class="account"><strong><%=v_custid%></strong></label>

</div>

<div class="form_row"> <label class="contact"><strong>Login ID:</strong></label> <label class="account"><strong><%=v_loginid%></strong></label> </div> <div class="form_row"> <label class="contact"><strong>Address:</strong></label> <label class="account"><strong><%=s1.getAddress()%></strong></label> </div> <div class="form_row"> <label class="contact"><strong>Phone:</strong></label> <label class="account"><strong><%=s1.getPhone()%></strong></label> </div> <div class="form_row"> <label class="contact"><strong>Mobile:</strong></label> <label class="account"><strong><%=s1.getMobile()%></strong></label> </div> <div class="form_row"> <label class="contact"><strong>Email:</strong></label> <label class="account"><strong><%=s1.getEmail()%></strong></label> </div> </div> </div> <div class="bottom_prod_box_big"></div>

</div> </div> <%} %> <%@ include file="right_menu.jsp" %> <%@ include file="footer.jsp" %> </div> </body>

SHOPPINGCART.JSP
<body> <%@ include file="header.jsp" %> <div id="main_container"> <%@ include file="members_left_menu.jsp" %> <div class="center_content"> <div class="center_title_bar">Shopping Cart</div> <%@ page import="java.util.*" %> <jsp:useBean id="s1" class="beans.Display" scope="page"/> <table width="90%" border="1" cellpadding="4" cellspacing="1" align="center"> <tr> <td>Product Title</td> <td>Quantity</td> <td>Price</td> <td>Total</td> <td>&nbsp;</td> </tr>

<% double gtotal=0; List<Object> list=new ArrayList<Object>(); list=s1.displayData("select cartid, prodtitle, qty, price, qty*price total from cart c, product p where c.prodid=p.prodid and custid=" + v_custid + " order by cartid desc"); for(int i=0; i<list.size();i++) { List<Object> crow=new ArrayList<Object>(); crow=(List)list.get(i); %> <tr> <%for(int j=1; j<crow.size();j++) {%> <td><%=crow.get(j)%></td> <%if(j==4){gtotal=gtotal+ Double.parseDouble((String)crow.get(4));} %> <%}%> <td><a href="deletecart.jsp?cartid=<%=crow.get(0)%>">Del</a></td> </tr> <%} %> <tr> <td colspan="3" align="right"><strong>Grand Total </strong></td> <td><strong><%=gtotal%></strong></td> <td>&nbsp;</td> </tr> </table>

<p>&nbsp;</p> <p>&nbsp;</p> <table width="80%" border="0" align="center" cellpadding="1" cellspacing="1"> <tr> <td align="center"><a href="products.jsp"><img src="images/contShopping.png" width="203" height="40" border="0" /></a></td> <%if(gtotal!=0) {%> <td align="center"><a href="checkout.jsp"><img src="images/checkout.png" width="203" height="40" border="0" /></a></td> <%} %> </tr> </table> <p>&nbsp;</p> </div> <%@ include file="right_menu.jsp" %> <%@ include file="footer.jsp" %> </div> </body>

ADMIN.JSP
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Mobile Store</title> <link rel="stylesheet" type="text/css" href="style.css" /> <script type="text/javascript" src="js/boxOver.js"></script> </head> <body> <%@ include file="header.jsp" %> <div id="main_container"> <div class="center_content"> <div class="center_title_bar">Admin Login</div> <div class="prod_box_big"> <div class="top_prod_box_big"></div> <div class="center_prod_box_big"> <form method="post" action="admin1.jsp"> <div class="contact_form"> <div class="form_row"> <font color="red"> <% String err=null; err=request.getParameter("err"); if(err!=null) { if(err.equals("1")) { out.println("Invalid Login ID or Password"); }

else if(err.equals("2")) { out.println("Session Expired. Please Login again"); } }%> </font></div> <div class="form_row"> <label class="contact"><strong>Login ID :</strong></label> <input name="loginid" type="text" class="contact_input" id="loginid" /> </div>

<div class="form_row"> <label class="contact"><strong>Password:</strong></label> <input name="password" type="password" class="contact_input" id="password" /> </div>

<div class="form_row"> <input type="submit" value="Login" class="contact"/> </div>

</div> </form>

</div>

<div class="bottom_prod_box_big"></div> </div> </div> </div> </body> </html>

DISPLAYORDERS.JSP
<body> <%@ include file="menu.jsp" %> <%@ page import="java.util.*" %> <jsp:useBean id="s1" class="beans.Display" scope="page"/> <table width="90%" border="1" cellpadding="4" cellspacing="1" align="center"> <tr> <td>Order ID</td> <td>Order date</td> <td>Customer Name</td> <td>Total Amount</td> <td>Status</td> <td>View Details</td> <td>Edit Status</td> </tr> <% List<Object> list=new ArrayList<Object>();

list=s1.displayData("select orderid, odate, custname, total, status from ordermaster o, customer c where o.custid=c.custid order by orderid desc"); for(int i=0; i<list.size();i++) { List<Object> crow=new ArrayList<Object>(); crow=(List)list.get(i); %> <tr> <%for(int j=0; j<crow.size();j++) {%> <td><%=crow.get(j)%></td> <%}%> <td><a href="displayorderdetails.jsp?orderid=<%=crow.get(0)%>">View Details</a></td> <td><a href="updateorder.jsp?orderid=<%=crow.get(0)%>">Edit Status</a></td> </tr> <%} %> </table> </body>

DISPLAYPRODUCTS.JSP
<body> <%@ include file="menu.jsp" %> <%@ page import="java.util.*" %> <jsp:useBean id="s1" class="beans.Display" scope="page"/> <table width="90%" border="1" cellpadding="4" cellspacing="1" align="center">

<tr> <td>Product ID</td> <td>Category</td> <td>Sub Category</td> <td>Title</td> <td>Detail</td> <td>Price</td> <td>Warranty</td> <td>Photo</td> <td>Edit</td> <td>Delete</td> </tr> <% List<Object> list=new ArrayList<Object>(); list=s1.displayData("select prodid, catname, scatname, prodtitle, detail, price, warranty from product p, subcategory s, category c where p.catid=c.catid and p.scatid= s.scatid order by prodid desc"); for(int i=0; i<list.size();i++) { List<Object> crow=new ArrayList<Object>(); crow=(List)list.get(i); %> <tr> <%for(int j=0; j<crow.size();j++) {%> <td><%=crow.get(j)%></td>

<%}%> <td><a href="uploadphoto.jsp?prodid=<%=crow.get(0)%>">Photo</a></td> <td><a href="updateproduct1.jsp?prodid=<%=crow.get(0)%>">Edit</a></td> <td><a href="deleteproduct1.jsp?prodid=<%=crow.get(0)%>">Delete</a></td> </tr> <%} %> </table> </body>

UPDATECATOGORY.JSP
<body> <%@ include file="menu.jsp" %> <% String err=null; err=request.getParameter("err"); if(err!=null) { if(!err.equals("")) { out.println("Invalid Record"); } } %> <form id="form1" name="form1" method="post" action="updatecategory1.jsp"> <table width="400" border="0" cellspacing="1" cellpadding="3"> <tr>

<td width="151">Category ID</td> <td width="234"><input name="catid" type="text" id="catid"/></td> </tr> <tr>

<tr> <td colspan="2" align="center"><input type="submit" name="Submit" value="Submit"/></td> </tr> </table> </form> </body>

UPLOADPHOTO.JSP
<body> <%@ include file="menu.jsp" %> <% String prodid; prodid=request.getParameter("prodid"); %> <form action="uploadphoto1.jsp" method="post" enctype="multipart/form-data"> <input name="prodid" type="hidden" value="<%=prodid %>"/><br/> Photo 1: <input name="photo1" type="file"/><br/> <input type="submit"/> </form> </body>

BEANS ADMIN.JAVA
package beans; import java.sql.*;

public class Admin { Connection con; String loginid=null; String password=null; String npwd=null; public Admin() { super(); } public String getLoginid() { return loginid; }

public void setLoginid(String loginid) { this.loginid = loginid; } public String getPassword() { return password; }

public void setPassword(String password) { this.password = password; } public String getNpwd() { return npwd; } public void setNpwd(String npwd) { this.npwd= npwd; } public boolean checkLogin()throws SQLException { boolean found=true; MyConnection db=new MyConnection(); con=db.openDatabase(); PreparedStatement pstmt=con.prepareStatement("select * from admin where loginid=? and password=?"); pstmt.setString(1,loginid); pstmt.setString(2,password); ResultSet rs=pstmt.executeQuery(); if(rs.next()) { found=true; } else {

found=false; } db.closeDatabase(con); return found; }

public boolean changePassword() throws SQLException {

boolean found=true; MyConnection db=new MyConnection(); con=db.openDatabase(); PreparedStatement ps=con.prepareStatement("select * from admin where loginid=? and password=?"); ps.setString(1,loginid); ps.setString(2,password);

ResultSet rs=ps.executeQuery(); if(rs.next()) { String sql="update admin set password=? where loginid=?"; PreparedStatement stmt=con.prepareStatement(sql); stmt.setString(1,npwd); stmt.setString(2,loginid); stmt.executeUpdate();

found=true; } else { found=false; } return found; } }

CART.JAVA
package beans;

import java.sql.*;

public class Cart { Connection con; int cartid, custid, prodid, qty; String sessionid, cdate;

public int getCartid() { return cartid; }

public void setCartid(int cartid) { this.cartid = cartid; }

public int getCustid() { return custid; }

public void setCustid(int custid) { this.custid = custid; }

public int getProdid() { return prodid; }

public void setProdid(int prodid) { this.prodid = prodid; }

public int getQty() { return qty; }

public void setQty(int qty) { this.qty = qty; }

public String getSessionid() { return sessionid; }

public void setSessionid(String sessionid) { this.sessionid = sessionid; }

public String getCdate() { return cdate; }

public void setCdate(String cdate) { this.cdate = cdate; } public void doInsert() throws SQLException {

MyConnection db=new MyConnection(); con=db.openDatabase();

PreparedStatement ps=con.prepareStatement("select * from cart where custid=? and prodid=?"); ps.setInt(1,custid); ps.setInt(2,prodid);

ResultSet rs=ps.executeQuery(); if(rs.next()) { PreparedStatement pstmt=con.prepareStatement("update cart set qty=qty+1 where prodid=?"); pstmt.setInt(1,prodid); pstmt.executeUpdate(); } else { PreparedStatement pstmt=con.prepareStatement("insert into cart(custid, sessionid, prodid, qty, cdate) values(?,?,?,?,?)"); pstmt.setInt(1,custid); pstmt.setString(2,sessionid); pstmt.setInt(3,prodid); pstmt.setInt(4,qty); java.util.Date now=new java.util.Date(); pstmt.setDate(5, new java.sql.Date(now.getTime())); pstmt.executeUpdate(); } db.closeDatabase(con);

} public void doDelete()throws SQLException { MyConnection db=new MyConnection(); con=db.openDatabase(); PreparedStatement pstmt=con.prepareStatement("delete from cart where cartid=?"); pstmt.setInt(1,cartid); pstmt.executeUpdate(); db.closeDatabase(con); } public void doDelete(int custid)throws SQLException { MyConnection db=new MyConnection(); con=db.openDatabase(); PreparedStatement pstmt=con.prepareStatement("delete from cart where custid=?"); pstmt.setInt(1,custid); pstmt.executeUpdate(); db.closeDatabase(con); } }

MYCONNECTION.JAVA
package beans;

import java.sql.*; class MyConnection { private String dbURL="jdbc:mysql://localhost:3306/mobile"; private String dbUserName="root"; private String dbpassword=""; MyConnection() { }

public String getDbURL() { return dbURL; } public void setDbURL(String dbURL) { this.dbURL = dbURL; } public String getDbUserName() { return dbUserName; } public void setDbUserName(String dbUserName) { this.dbUserName = dbUserName; } public String getDbpassword() { return dbpassword; }

public void setDbpassword(String dbpassword) { this.dbpassword = dbpassword; } public Connection openDatabase() { Connection conn=null; try { Class.forName("com.mysql.jdbc.Driver"); conn=DriverManager.getConnection(getDbURL(),getDbUserName(),getDbpassword()); } catch(Exception e) { System.out.println("Could not connect to DB"); e.printStackTrace(); } return conn; } public void closeDatabase(Connection conn) { if(conn!=null) { try {

conn.close(); } catch(SQLException e) { System.out.println("Enable to close DB connection"); e.printStackTrace(); } } }

You might also like