300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 智能手机销售网后台管理系统手机销售网程序设计

智能手机销售网后台管理系统手机销售网程序设计

时间:2023-10-22 14:21:54

相关推荐

智能手机销售网后台管理系统手机销售网程序设计

智能手机销售网后台管理系统手机销售网程序设计

信管117136钟晓威

数据库设计功能实现后台设计dtree实现树形菜单
数据库设计数据库连接

try{ String uri= "jdbc:mysql://127.0.0.1/mobileshop";

String user="root";

String password="";

con=DriverManager.getConnection(uri,user,password);

sql=con.createStatement();

系统管理

head.txt<%@ page contentType="text/html;charset=GB2312" %><div align="center"><H2>“智多星”智能手机销售网</H2><table cellSpacing="1" cellPadding="1" width="660" align="center" border="0" ><tr valign="bottom"><td><A href="inputRegisterMess.jsp"><font size=2>注册</font></A></td><td><A href="login.jsp"><font size=2>登录</font></A></td><td><A href="lookMobile.jsp"><font size=2>浏览手机</font></A></td><td><A href="searchMobile.jsp"><font size=2>查询手机</font></A></td><td><A href="lookShoppingCar.jsp"><font size=2>查看购物车</font></A></td><td><A href="lookOrderForm.jsp"><font size=2>查看订单</font></A></td><td><A href="exitServlet"><font size=2>退出</font></A></td><td><A href="index.jsp"><font size=2>主页</font></A></td><td><A href="houtai.jsp"><font size=2>后台管理</font></A></td></tr></Font></table></div>

index.jsp<%@ page contentType="text/html;charset=GB2312" %><HTML> <BODY><HEAD><%@ include file="head.txt" %></HEAD><title>首页</title><CENTER> <h1><font Size=4 color=blue>欢迎光临“智多星”智能手机销售网</font></h1><img src="image/welcome.jpg" width=500 height=400 ></img></CENTER></BODY></HTML>

web.xml

<?xml version="1.0" encoding="ISO-8859-1" ?><web-app><servlet> <servlet-name>registerServlet</servlet-name><servlet-class>myservlet.control.HandleRegister</servlet-class></servlet><servlet-mapping><servlet-name>registerServlet</servlet-name><url-pattern>/registerServlet</url-pattern></servlet-mapping><servlet><servlet-name>loginServlet</servlet-name><servlet-class>myservlet.control.HandleLogin</servlet-class></servlet><servlet-mapping><servlet-name>loginServlet</servlet-name><url-pattern>/loginServlet</url-pattern></servlet-mapping><servlet><servlet-name>deleteServlet</servlet-name><servlet-class>myservlet.control.HandleDelete</servlet-class></servlet><servlet-mapping><servlet-name>deleteServlet</servlet-name><url-pattern>/deleteServlet</url-pattern></servlet-mapping><servlet><servlet-name>buyServlet</servlet-name><servlet-class>myservlet.control.HandleBuyGoods</servlet-class></servlet><servlet-mapping><servlet-name>buyServlet</servlet-name><url-pattern>/buyServlet</url-pattern></servlet-mapping><servlet><servlet-name>queryServlet</servlet-name><servlet-class>myservlet.control.QueryAllRecord</servlet-class></servlet><servlet-mapping><servlet-name>queryServlet</servlet-name><url-pattern>/queryServlet</url-pattern></servlet-mapping><servlet><servlet-name>putGoodsServlet</servlet-name><servlet-class>myservlet.control.PutGoodsToCar</servlet-class></servlet><servlet-mapping><servlet-name>putGoodsServlet</servlet-name><url-pattern>/putGoodsServlet</url-pattern></servlet-mapping><servlet><servlet-name>searchByConditionServlet</servlet-name><servlet-class>myservlet.control.SearchByCondition</servlet-class></servlet><servlet-mapping><servlet-name>searchByConditionServlet</servlet-name><url-pattern>/searchByConditionServlet</url-pattern></servlet-mapping><servlet><servlet-name>exitServlet</servlet-name><servlet-class>myservlet.control.HandleExit</servlet-class></servlet><servlet-mapping><servlet-name>exitServlet</servlet-name><url-pattern>/exitServlet</url-pattern></servlet-mapping></web-app>

会员注册inputRegisterMess.jsp

<%@ page contentType="text/html;charset=GB2312" %><jsp:useBean id="userBean" class="mybean.data.Register" scope="request"/><HEAD><%@ include file="head.txt" %></HEAD><title>注册页面</title><HTML><BODY bgcolor=pink><Font size=2><div align="center"><FORM action="registerServlet" method="post" name=form><table>用户名由字母、数字、下划线构成,*注释的项必须填写。<tr><td>*用户名称:</td><td><Input type=text name="logname" ></td><td>*用户密码:</td><td><Input type=password name="password"></td></tr><tr><td>*重复密码:</td><td><Input type=password name="again_password"></td><td>联系电话:</td><td><Input type=text name="phone"></td></tr><tr><td>邮寄地址:</td><td><Input type=text name="address"></td><td>真实姓名:</td><td><Input type=text name="realname"></td><td><Input type=submit name="g" value="提交"></td> </tr></table></Form></div ><div align="center"><p> 注册反馈:<jsp:getProperty name="userBean" property="backNews" /> <table border=3><tr><td>会员名称:</td><td><jsp:getProperty name="userBean" property="logname"/></td></tr><tr><td>姓名:</td><td><jsp:getProperty name="userBean" property="realname"/></td></tr><tr><td>地址:</td><td><jsp:getProperty name="userBean" property="address"/></td></tr><tr><td>电话:</td><td><jsp:getProperty name="userBean" property="phone"/></td></tr></table></div ></Body></HTML>

Register.java

package mybean.data;public class Register{ String logname="" , phone="",address="",realname="",backNews="请输入信息"; public void setLogname(String logname){ this.logname=logname;}public String getLogname(){ return logname;}public void setPhone(String phone){ this.phone=phone;}public String getPhone(){ return phone;}public void setAddress(String address){ this.address=address;}public String getAddress(){ return address;}public void setRealname(String realname){ this.realname=realname;}public String getRealname(){ return realname;}public void setBackNews(String backNews){ this.backNews=backNews;}public String getBackNews(){ return backNews;}}

HandleRegister.java

package myservlet.control;import mybean.data.*;import java.sql.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class HandleRegister extends HttpServlet {public void init(ServletConfig config) throws ServletException { super.init(config);try { Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){} }public String handleString(String s){ try{ byte bb[]=s.getBytes("iso-8859-1");s=new String(bb);}catch(Exception ee){} return s; }public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {String uri="jdbc:mysql://127.0.0.1/mobileshop?"+"user=root&password=&characterEncoding=gb2312";Connection con; PreparedStatement sql; Register userBean=new Register(); //创建的Javabean模型request.setAttribute("userBean",userBean);String logname=request.getParameter("logname").trim();String password=request.getParameter("password").trim();String again_password=request.getParameter("again_password").trim();String phone=request.getParameter("phone").trim();String address=request.getParameter("address").trim();String realname=request.getParameter("realname").trim();if(logname==null)logname="";if(password==null)password="";if(!password.equals(again_password)) { userBean.setBackNews("两次密码不同,注册失败,");RequestDispatcher dispatcher= request.getRequestDispatcher("inputRegisterMess.jsp");dispatcher.forward(request, response);//转发return;}boolean isLD=true;for(int i=0;i<logname.length();i++){char c=logname.charAt(i);if(!((c<='z'&&c>='a')||(c<='Z'&&c>='A')||(c<='9'&&c>='0'))) isLD=false;} boolean boo=logname.length()>0&&password.length()>0&&isLD;String backNews="";try{ con=DriverManager.getConnection(uri);String insertCondition="INSERT INTO user VALUES (?,?,?,?,?)";sql=con.prepareStatement(insertCondition);if(boo){ sql.setString(1,handleString(logname));sql.setString(2,handleString(password));sql.setString(3,handleString(phone));sql.setString(4,handleString(address));sql.setString(5,handleString(realname));int m=sql.executeUpdate();if(m!=0){backNews="注册成功";userBean.setBackNews(backNews);userBean.setLogname(logname);userBean.setPhone(handleString(phone));userBean.setAddress(handleString(address));userBean.setRealname(handleString(realname));}}else {backNews="信息填写不完整或名字中有非法字符";userBean.setBackNews(backNews); }con.close();}catch(SQLException exp){backNews="该会员名已被使用,请您更换名字"+exp;userBean.setBackNews(backNews); }RequestDispatcher dispatcher= request.getRequestDispatcher("inputRegisterMess.jsp");dispatcher.forward(request, response);//转发}public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException {doPost(request,response);}}

会员登陆

login.jsp

<%@ page contentType="text/html;charset=GB2312" %><jsp:useBean id="loginBean" class="mybean.data.Login" scope="session"/><HTML><HEAD><%@ include file="head.txt" %></HEAD><BODY bgcolor=pink><font size=2><div align="center"><FORM action="loginServlet" Method="post"><table border=2><tr> <th>登录</th></tr><tr><td>登录名称:<Input type=text name="logname"></td></tr><tr><td>输入密码:<Input type=password name="password"></td></tr></table><Input type=submit name="g" value="提交"></form></div><div align="center" >登录反馈信息:<br><jsp:getProperty name="loginBean" property="backNews"/><br>登录名称:<br><jsp:getProperty name="loginBean" property="logname"/></div></font></BODY></HTML>

Login.java

package mybean.data;import java.util.*;public class Login {String logname="",backNews="未登录";LinkedList<String> car; //用户的购物车public Login() {car = new LinkedList<String>();}public void setLogname(String logname){ this.logname = logname;}public String getLogname(){return logname;}public void setBackNews(String s) {backNews = s;} public String getBackNews(){return backNews;}public LinkedList<String> getCar() { return car;}}

HandleLogin.java

package myservlet.control;import mybean.data.*;import java.sql.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.util.*;public class HandleLogin extends HttpServlet{public void init(ServletConfig config) throws ServletException{super.init(config);try{ Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){} }public String handleString(String s){try{ byte bb[]=s.getBytes("iso-8859-1");s=new String(bb);}catch(Exception ee){} return s; }public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{Connection con; Statement sql; String logname=request.getParameter("logname").trim(),password=request.getParameter("password").trim();logname=handleString(logname);password=handleString(password);String uri="jdbc:mysql://127.0.0.1/mobileshop?"+"user=root&password=&characterEncoding=gb2312";boolean boo=(logname.length()>0)&&(password.length()>0); try{ con=DriverManager.getConnection(uri);String condition="select * from user where logname = '"+logname+"' and password ='"+password+"'";sql=con.createStatement(); if(boo){ResultSet rs=sql.executeQuery(condition);boolean m=rs.next();if(m==true){ //调用登录成功的方法:success(request,response,logname,password); RequestDispatcher dispatcher=request.getRequestDispatcher("login.jsp");//转发dispatcher.forward(request,response);}else{String backNews="您输入的用户名不存在,或密码不般配";//调用登录失败的方法:fail(request,response,logname,backNews); }}else{String backNews="请输入用户名和密码";fail(request,response,logname,backNews);}con.close();}catch(SQLException exp){String backNews=""+exp;fail(request,response,logname,backNews);}}public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{doPost(request,response);}public void success(HttpServletRequest request,HttpServletResponse response,String logname,String password) {Login loginBean=null;HttpSession session=request.getSession(true);try{ loginBean=(Login)session.getAttribute("loginBean");if(loginBean==null){loginBean=new Login(); //创建新的数据模型 session.setAttribute("loginBean",loginBean);loginBean=(Login)session.getAttribute("loginBean");}String name =loginBean.getLogname();if(name.equals(logname)) {loginBean.setBackNews(logname+"已经登录了");loginBean.setLogname(logname);}else { //数据模型存储新的登录用户loginBean.setBackNews(logname+"登录成功");loginBean.setLogname(logname);}}catch(Exception ee){loginBean=new Login(); session.setAttribute("loginBean",loginBean);loginBean.setBackNews(logname+"登录成功");loginBean.setLogname(logname);}}public void fail(HttpServletRequest request,HttpServletResponse response,String logname,String backNews) {response.setContentType("text/html;charset=GB2312");try {PrintWriter out=response.getWriter();out.println("<html><body>");out.println("<h2>"+logname+"登录反馈结果<br>"+backNews+"</h2>") ;out.println("返回登录页面或主页<br>");out.println("<a href =login.jsp>登录页面</a>");out.println("<br><a href =index.jsp>主页</a>");out.println("</body></html>");}catch(IOException exp){}}}

浏览手机

lookMoblie.jsp

<%@ page contentType="text/html;charset=GB2312" %><%@ page import="java.sql.*" %><HTML><HEAD><%@ include file="head.txt" %></HEAD><BODY bgcolor=cyan><font size=2><div align="center"><h2>选择某类手机<br>分页显示这类手机</h2><% try { Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){} String uri="jdbc:mysql://127.0.0.1/mobileshop?"+"user=root&password=&characterEncoding=gb2312";Connection con; Statement sql;ResultSet rs;try {con=DriverManager.getConnection(uri);sql=con.createStatement();//读取mobileClassify表,获得分类: rs=sql.executeQuery("SELECT * FROM mobileClassify ");out.print("<form action='queryServlet' method ='post'>") ;out.print("<select name='fenleiNumber'>") ;while(rs.next()){int id = rs.getInt(1);String mobileCategory = rs.getString(2);out.print("<option value ="+id+">"+mobileCategory+"</option>");} out.print("</select>");out.print("<input type ='submit' value ='提交'>"); out.print("</form>");con.close();}catch(SQLException e){ out.print(e);}%></div></font></BODY></HTML>

byPageShow.jsp

<%@ page contentType="text/html;charset=GB2312" %><%@ page import="mybean.data.DataByPage" %><%@ page import="com.sun.rowset.*" %><jsp:useBean id="dataBean" class="mybean.data.DataByPage" scope="session"/><%@ include file="head.txt" %></HEAD><HTML><Body bgcolor=#66FFAA><center><BR>当前显示的内容是:<table border=2><tr><th>手机标识号</th><th>手机名称</th><th>手机制造商</th><th>手机价格</th><th>查看详情</th><td><font color=blue>添加到购物车</font></td></tr><jsp:setProperty name="dataBean" property="pageSize" param="pageSize"/><jsp:setProperty name="dataBean" property="currentPage" param="currentPage"/><% CachedRowSetImpl rowSet=dataBean.getRowSet();if(rowSet==null) {out.print("没有查询到结果,无法浏览");return; }rowSet.last(); int totalRecord=rowSet.getRow();out.println("全部记录数"+totalRecord); //全部记录数int pageSize=dataBean.getPageSize(); //每页显示的记录数int totalPages = dataBean.getTotalPages();if(totalRecord%pageSize==0)totalPages = totalRecord/pageSize;//总页数elsetotalPages = totalRecord/pageSize+1;dataBean.setPageSize(pageSize);dataBean.setTotalPages(totalPages);if(totalPages>=1) {if(dataBean.getCurrentPage()<1)dataBean.setCurrentPage(dataBean.getTotalPages());if(dataBean.getCurrentPage()>dataBean.getTotalPages())dataBean.setCurrentPage(1);int index=(dataBean.getCurrentPage()-1)*pageSize+1;rowSet.absolute(index); //查询位置移动到currentPage页起始位置boolean boo=true;for(int i=1;i<=pageSize&&boo;i++) { String number=rowSet.getString(1);String name=rowSet.getString(2);String maker=rowSet.getString(3);String price=rowSet.getString(4);String goods ="("+number+","+name+","+maker+","+price+")#"+price;//便于购物车计算价格,尾缀上"#价格值"goods = goods.replaceAll("\\p{Blank}","");String button="<form action='putGoodsServlet' method = 'post'>"+"<input type ='hidden' name='java' value= "+goods+">"+"<input type ='submit' value='放入购物车' ></form>";String detail="<form action='showDetail.jsp' method = 'post'>"+"<input type ='hidden' name='xijie' value= "+number+">"+"<input type ='submit' value='查看细节' ></form>";out.print("<tr>");out.print("<td>"+number+"</td>");out.print("<td>"+name+"</td>");out.print("<td>"+maker+"</td>");out.print("<td>"+price+"</td>");out.print("<td>"+detail+"</td>");out.print("<td>"+button+"</td>");out.print("</tr>");boo=rowSet.next();}}%></table><BR>每页最多显示<jsp:getProperty name="dataBean" property="pageSize"/>条信息<BR>当前显示第<Font color=blue><jsp:getProperty name="dataBean" property="currentPage"/></Font>页,共有<Font color=blue><jsp:getProperty name="dataBean" property="totalPages"/></Font>页。<Table><tr><td><FORM action="" method=post><Input type=hidden name="currentPage" value="<%=dataBean.getCurrentPage()-1 %>"><Input type=submit name="g" value="上一页"></FORM></td><td><FORM action="" method=post><Input type=hidden name="currentPage"value="<%=dataBean.getCurrentPage()+1 %>"><Input type=submit name="g" value="下一页"></FORM></td></tr><tr><td> <FORM action="" method=post>每页显示<Input type=text name="pageSize" value =2 size=3>条记录<Input type=submit name="g" value="确定"></FORM></td><td> <FORM action="" method=post>输入页码:<Input type=text name="currentPage" size=2 ><Input type=submit name="g" value="提交"></FORM></td></tr></Table></Center></BODY></HTML>

showDatail.jsp

<%@ page contentType="text/html;charset=GB2312" %><%@ page import="mybean.data.Login" %><%@ page import="java.sql.*" %><jsp:useBean id="loginBean" class="mybean.data.Login" scope="session"/><%@ include file="head.txt" %></HEAD><HTML><Body bgcolor=#99FFCC ><center><% if(loginBean==null){response.sendRedirect("login.jsp");//重定向到登录页面}else {boolean b =loginBean.getLogname()==null||loginBean.getLogname().length()==0;if(b)response.sendRedirect("login.jsp");//重定向到登录页面}String mobileID = request.getParameter("xijie"); out.print("<th>产品号"+mobileID);if(mobileID==null) {out.print("没有产品号,无法查看细节");return;} Connection con;Statement sql; ResultSet rs;try { Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){} String uri="jdbc:mysql://127.0.0.1/mobileshop";try{ con=DriverManager.getConnection(uri,"root","");sql=con.createStatement();String cdn="SELECT * FROM mobileForm where mobile_version = '"+mobileID+"'";rs=sql.executeQuery(cdn);out.print("<table border=2>");out.print("<tr>");out.print("<th>产品号");out.print("<th>名称");out.print("<th>制造商");out.print("<th>价格");out.print("<th><font color=blue>放入购物车</font>");out.print("</TR>");String picture="welcome.jpg";String detailMess="";while(rs.next()){String number=rs.getString(1);String name=rs.getString(2);String maker=rs.getString(3);String price=rs.getString(4);detailMess=rs.getString(5);picture=rs.getString(6); String goods ="("+number+","+name+","+maker+","+price+")#"+price;//便于购物车计算价格,尾缀上"#价格值"goods = goods.replaceAll("\\p{Blank}","");String button="<form action='putGoodsServlet' method = 'post'>"+"<input type ='hidden' name='java' value= "+goods+">"+"<input type ='submit' value='放入购物车' ></form>";out.print("<tr>");out.print("<td>"+number+"</td>");out.print("<td>"+name+"</td>");out.print("<td>"+maker+"</td>");out.print("<td>"+price+"</td>");out.print("<td>"+button+"</td>");out.print("</tr>");} out.print("</table>");out.print("产品详情:<br>");out.println("<div align=center>"+detailMess+"<div>");String pic ="<img src='image/"+picture+"' width=260 height=200 ></img>";out.print(pic); //产片图片con.close(); }catch(SQLException exp){}%></Center></BODY></HTML>

DataByPage.java

package mybean.data;import com.sun.rowset.*; public class DataByPage{CachedRowSetImpl rowSet=null; //存储表中全部记录的行集对象int pageSize=1; //每页显示的记录数int totalPages=1; //分页后的总页数int currentPage =1 ; //当前显示页 public void setRowSet(CachedRowSetImpl set){rowSet=set;}public CachedRowSetImpl getRowSet(){return rowSet;}public void setPageSize(int size){pageSize=size;}public int getPageSize(){return pageSize;} public int getTotalPages(){return totalPages;} public void setTotalPages(int n){totalPages=n; }public void setCurrentPage(int n){currentPage =n;}public int getCurrentPage(){return currentPage ;}}

QueryAllRecord.java

package myservlet.control;import mybean.data.DataByPage;import com.sun.rowset.*;import java.sql.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class QueryAllRecord extends HttpServlet{CachedRowSetImpl rowSet=null;public void init(ServletConfig config) throws ServletException{super.init(config);try { Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){} }public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{request.setCharacterEncoding("gb2312");String idNumber= request.getParameter("fenleiNumber");if(idNumber==null) idNumber="0";int id = Integer.parseInt(idNumber);HttpSession session=request.getSession(true); Connection con=null; DataByPage dataBean=null;try{ dataBean=(DataByPage)session.getAttribute("dataBean");if(dataBean==null){dataBean=new DataByPage(); //创建Javabean对象session.setAttribute("dataBean",dataBean);}}catch(Exception exp){dataBean=new DataByPage(); session.setAttribute("dataBean",dataBean);} String uri="jdbc:mysql://127.0.0.1/mobileshop";try{ con=DriverManager.getConnection(uri,"root","");Statement sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);ResultSet rs=sql.executeQuery("SELECT * FROM mobileForm where id = "+id);rowSet=new CachedRowSetImpl(); //创建行集对象rowSet.populate(rs);dataBean.setRowSet(rowSet);//行集数据存储在dataBean中 con.close(); //关闭连接}catch(SQLException exp){}response.sendRedirect("byPageShow.jsp");//重定向到byPageShow.jsp} public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{doPost(request,response);}}

PutGoodsToCar.java

package myservlet.control;import mybean.data.Login;import java.util.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class PutGoodsToCar extends HttpServlet {public void init(ServletConfig config) throws ServletException { super.init(config);}public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {request.setCharacterEncoding("gb2312");String goods = request.getParameter("java");System.out.println(goods);Login loginBean=null;HttpSession session=request.getSession(true);try{ loginBean=(Login)session.getAttribute("loginBean");boolean b =loginBean.getLogname()==null||loginBean.getLogname().length()==0;if(b)response.sendRedirect("login.jsp");//重定向到登录页面LinkedList<String> car = loginBean.getCar();car.add(goods);speakSomeMess(request,response,goods); }catch(Exception exp){response.sendRedirect("login.jsp");//重定向到登录页面}}public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException {doPost(request,response);}public void speakSomeMess(HttpServletRequest request,HttpServletResponse response,String goods) {response.setContentType("text/html;charset=GB2312");try {PrintWriter out=response.getWriter();out.print("<%@ include file='head.txt' %></HEAD>");out.println("<html><body>");out.println("<h2>"+goods+"放入购物车</h2>") ;out.println("查看购物车或返回<br>");out.println("<a href =lookShoppingCar.jsp>查看购物车</a>");out.println("<br><a href =byPageShow.jsp>主页</a>");out.println("</body></html>");}catch(IOException exp){}}}

查看购物车

lookShoppingCar.jsp

<%@ page contentType="text/html;charset=GB2312" %><%@ page import="mybean.data.Login" %><%@ page import="java.util.*" %><jsp:useBean id="loginBean" class="mybean.data.Login" scope="session"/><HTML><HEAD><%@ include file="head.txt" %></HEAD><BODY bgcolor=yellow><font size=2><div align="center"><% if(loginBean==null){response.sendRedirect("login.jsp");//重定向到登录页面}else {boolean b =loginBean.getLogname()==null||loginBean.getLogname().length()==0;if(b)response.sendRedirect("login.jsp");//重定向到登录页面}LinkedList car =loginBean.getCar();if(car==null)out.print("<h2> 购物车没有物品.</h2>");else {Iterator<String> iterator=car.iterator();StringBuffer buyGoods = new StringBuffer();int n=0;double priceSum =0;out.print("购物车中的物品:<table border=2>");while(iterator.hasNext()) {String goods=iterator.next();String showGoods="";n++; //购车车物品的后缀是“#价格数字",比如“iPhone手机价格3989 #3989”int index=goods.lastIndexOf("#");if(index!=-1){priceSum+=Double.parseDouble(goods.substring(index+1));showGoods = goods.substring(0,index);}buyGoods.append(n+":"+showGoods);String del="<form action='deleteServlet' method = 'post'>"+"<input type ='hidden' name='delete' value= "+goods+">"+"<input type ='submit' value='删除' ></form>";out.print("<tr><td>"+showGoods+"</td>");out.print("<td>"+del+"</td></tr>");}out.print("</table>");String orderForm = "<form action='buyServlet' method='post'>"+" <input type ='hidden' name='buy' value= "+buyGoods+" >"+ " <input type ='hidden' name='price' value= "+priceSum+" >"+ "<input type ='submit' value='生成订单'></form>";out.print(orderForm); } %></div></font></BODY></HTML>

HandDelete.java

package myservlet.control;import mybean.data.Login;import java.util.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class HandleDelete extends HttpServlet {public void init(ServletConfig config) throws ServletException { super.init(config);}public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {request.setCharacterEncoding("gb2312");String delete = request.getParameter("delete");Login loginBean=null;HttpSession session=request.getSession(true);try{ loginBean=(Login)session.getAttribute("loginBean");boolean b =loginBean.getLogname()==null||loginBean.getLogname().length()==0;if(b)response.sendRedirect("login.jsp");//重定向到登录页面LinkedList<String> car = loginBean.getCar();car.remove(delete);}catch(Exception exp){response.sendRedirect("login.jsp");//重定向到登录页面}RequestDispatcher dispatcher= request.getRequestDispatcher("lookShoppingCar.jsp");dispatcher.forward(request, response);//转发 }public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException {doPost(request,response);}}

HandleBuyGoods.java

package myservlet.control;import mybean.data.Login;import java.sql.*;import java.util.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class HandleBuyGoods extends HttpServlet {public void init(ServletConfig config) throws ServletException { super.init(config);try{ Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){} }public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {request.setCharacterEncoding("gb2312");String buyGoodsMess = request.getParameter("buy");if(buyGoodsMess==null||buyGoodsMess.length()==0) {fail(request,response,"购物车没有物品,无法生成订单"); return;}String price = request.getParameter("price");if(price==null||price.length()==0) {fail(request,response,"没有计算价格和,无法生成订单"); return;}float sum = Float.parseFloat(price);Login loginBean=null;HttpSession session=request.getSession(true);try{ loginBean=(Login)session.getAttribute("loginBean");boolean b =loginBean.getLogname()==null||loginBean.getLogname().length()==0;if(b)response.sendRedirect("login.jsp");//重定向到登录页面}catch(Exception exp){response.sendRedirect("login.jsp");//重定向到登录页面}String uri="jdbc:mysql://127.0.0.1/mobileshop?"+"user=root&password=&characterEncoding=gb2312";Connection con; PreparedStatement sql;try{ con=DriverManager.getConnection(uri);String insertCondition="INSERT INTO orderform VALUES (?,?,?,?)";sql=con.prepareStatement(insertCondition);sql.setInt(1,0); //订单序号会自定增加sql.setString(2,loginBean.getLogname());sql.setString(3,buyGoodsMess);sql.setFloat(4,sum);sql.executeUpdate();LinkedList car=loginBean.getCar();car.clear(); //清空购物车success(request,response,"生成订单成功");}catch(SQLException exp){fail(request,response,"生成订单失败"+exp);}}public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException {doPost(request,response);}public void success(HttpServletRequest request,HttpServletResponse response,String backNews) {response.setContentType("text/html;charset=GB2312");try {PrintWriter out=response.getWriter();out.println("<html><body>");out.println("<h2>"+backNews+"</h2>") ;out.println("返回主页<br>");out.println("<br><a href =index.jsp>主页</a>");out.println("查看订单<br>");out.println("<br><a href =lookOrderForm.jsp>查看订单</a>");out.println("</body></html>");}catch(IOException exp){}}public void fail(HttpServletRequest request,HttpServletResponse response,String backNews) {response.setContentType("text/html;charset=GB2312");try {PrintWriter out=response.getWriter();out.println("<html><body>");out.println("<h2>"+backNews+"</h2>") ;out.println("返回主页:");out.println("<a href =index.jsp>主页</a>");out.println("</body></html>");}catch(IOException exp){}}}

查询手机

searMobile.jsp

<%@ page contentType="text/html;charset=GB2312" %><HTML><HEAD><%@ include file="head.txt" %></HEAD><BODY bgcolor=#55BBDD><font size=2><div align="center"><br>查询时可以输入手机的版本号或手机名称及价格。<br>手机名称支持模糊查询。<br>输入价格是在2个值之间的价格,格式是:价格1-价格2<br>例如 3987-8976 <FORM action="searchByConditionServlet" Method="post" ><br>输入查询信息:<Input type=text name="searchMess"><br><Input type =radio name="radio" value="mobile_version">手机版本号<Input type =radio name="radio" value="mobile_name" checked="ok">手机名称<Input type =radio name="radio" value="mobile_price">手机价格<br><Input type=submit name="g" value="提交"></Form></div></Font></BODY></HTML>

SearchByCondition.jsp

package myservlet.control;import mybean.data.DataByPage;import com.sun.rowset.*;import java.sql.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class SearchByCondition extends HttpServlet{CachedRowSetImpl rowSet=null;public void init(ServletConfig config) throws ServletException{super.init(config);try { Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){} }public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{request.setCharacterEncoding("gb2312");String searchMess= request.getParameter("searchMess");String radioMess= request.getParameter("radio");if(searchMess==null||searchMess.length()==0) {fail(request,response,"没有查询信息,无法查询");return;}String condition="";if(radioMess.equals("mobile_version")) {condition = "SELECT * FROM mobileForm where mobile_version ='"+searchMess+"'";}else if(radioMess.equals("mobile_name")) {condition = "SELECT * FROM mobileForm where mobile_name LIKE '%"+searchMess+"%'"; }else if(radioMess.equals("mobile_price")) {double max=0,min=0;String regex = "[^0123456789.]";String [] priceMess =searchMess.split(regex);if(priceMess.length==1) {max =min = Double.parseDouble(priceMess[0]);}else if(priceMess.length==2) {min = Double.parseDouble(priceMess[0]);max = Double.parseDouble(priceMess[1]);if(max<min) {double t = max;max = min;min = t;}}else {fail(request,response,"输入的价格格式有错误");return; }condition = "SELECT * FROM mobileForm where "+"mobile_price <= "+max+" AND mobile_price>="+min ;}HttpSession session=request.getSession(true); Connection con=null; DataByPage dataBean=null;try{ dataBean=(DataByPage)session.getAttribute("dataBean");if(dataBean==null){dataBean=new DataByPage(); //创建Javabean对象session.setAttribute("dataBean",dataBean);}}catch(Exception exp){dataBean=new DataByPage(); session.setAttribute("dataBean",dataBean);} String uri = "jdbc:mysql://127.0.0.1/mobileshop?"+"user=root&password=&characterEncoding=gb2312";try{ con=DriverManager.getConnection(uri);Statement sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);ResultSet rs=sql.executeQuery(condition);rowSet=new CachedRowSetImpl(); //创建行集对象rowSet.populate(rs);dataBean.setRowSet(rowSet);//行集数据存储在dataBean中 con.close(); //关闭连接}catch(SQLException exp){}response.sendRedirect("byPageShow.jsp");//重定向到byPageShow.jsp} public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{doPost(request,response);}public void fail(HttpServletRequest request,HttpServletResponse response,String backNews) {response.setContentType("text/html;charset=GB2312");try {PrintWriter out=response.getWriter();out.println("<html><body>");out.println("<h2>"+backNews+"</h2>") ;out.println("返回:");out.println("<a href =searchMobile.jsp>查询手机</a>");out.println("</body></html>");}catch(IOException exp){}}}

查询订单

lookOrderForm.jsp

<%@ page contentType="text/html;charset=GB2312" %><%@ page import="mybean.data.Login" %><jsp:useBean id="loginBean" class="mybean.data.Login" scope="session"/><%@ page import="java.sql.*" %><HTML><HEAD><%@ include file="head.txt" %></HEAD><div align="center"><% if(loginBean==null){response.sendRedirect("login.jsp");//重定向到登录页面}else {boolean b =loginBean.getLogname()==null||loginBean.getLogname().length()==0;if(b)response.sendRedirect("login.jsp");//重定向到登录页面}Connection con;Statement sql; ResultSet rs;try{ Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){}try { String uri= "jdbc:mysql://127.0.0.1/mobileshop";String user="root";String password="";con=DriverManager.getConnection(uri,user,password);sql=con.createStatement();String cdn="SELECT id,mess,sum FROM orderform where logname= '"+loginBean.getLogname()+"'";rs=sql.executeQuery(cdn);out.print("<table border=2>");out.print("<tr>");out.print("<th width=100>"+"订单号");out.print("<th width=100>"+"信息");out.print("<th width=100>"+"价格");out.print("</TR>");while(rs.next()){out.print("<tr>");out.print("<td >"+rs.getString(1)+"</td>"); out.print("<td >"+rs.getString(2)+"</td>");out.print("<td >"+rs.getString(3)+"</td>");out.print("</tr>") ; }out.print("</table>");con.close();}catch(SQLException e){ out.print(e);}%></div"></BODY></HTML>

退出登陆

HandleExit.java

package myservlet.control;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class HandleExit extends HttpServlet { public void init(ServletConfig config) throws ServletException{super.init(config);}public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {HttpSession session=request.getSession(true); session.invalidate(); //销毁用户的session对象response.sendRedirect("index.jsp"); //返回主页 }public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {doPost(request,response);}}

后台管理系统

页面布局的实现

index.html<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>手机后台管理系统</title></head><frameset rows="7%,90%,*"><frame src="top.html"><frameset cols="20%,*"><frame src="left.html"><frame src="main.html" name="main"></frameset><frame src="cpright.html"></frameset></html>

left.html<!DOCTYPE html><html><head><meta charset="UTF-8"><title>菜单</title><link rel="StyleSheet" href="dtree.css" type="text/css" /><script type="text/javascript" src="dtree.js"></script></head><body><div class="dtree"><a href="javascript: d.openAll();">展开所有</a> | <a href="javascript: d.closeAll();">关闭所有</a><script type="text/javascript">d = new dTree('d');d.add(0,-1,'“智多星”智能手机销售网后台管理系统');d.add(1,0,'查询所有表信息','example6_2.jsp','','main');d.add(2,0,'菜单','example01.html','','main');d.add(3,0,'-----用户-----');d.add(17,3,'查询用户表信息','example6_2.jsp','','main');d.add(4,3,'修改用户信息','example6_8.jsp','','main');d.add(5,3,'删除用户信息','delete1.jsp','','main');d.add(6,0,'---产品分类---');d.add(18,6,'查询分类表信息','example6_2.jsp','','main');d.add(7,6,'修改产品分类','example6_9.jsp','','main');d.add(8,6,'删除产品分类','delete2.jsp','','main');d.add(9,0,'-----产品-----');d.add(19,9,'查询产品表信息','example6_2.jsp','','main');d.add(10,9,'修改产品','example6_10.jsp','','main');d.add(11,9,'删除产品','delete3.jsp','','main');d.add(12,0,'-----订单-----');d.add(20,12,'查询订单表信息','example6_2.jsp','','main');d.add(13,12,'修改订单','example6_7.jsp','','main');d.add(14,12,'删除订单','delete4.jsp','','main');d.add(21,0,'-----设置-----');d.add(22,21,'返回主页','index.jsp','','main');d.add(23,21,'退出登陆','exitServlet','','main');d.add(24,0,'-----退出-----','index.jsp','','index.jsp');document.write(d);</script></div></body></html>

效果截图

main.html<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title></head><body></body></html>

top.html<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title></head><body><div align="center" ><font size="4" color="green" ;>“智多星”智能手机销售网后台管理系统</font></div></body></html>

cpright.html<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title></head><body></body></html>

树形菜单的实现

dtree.css.dtree {font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;font-size: 11px;color: #666;white-space: nowrap;}.dtree img {border: 0px;vertical-align: middle;}.dtree a {color: #333;text-decoration: none;}.dtree a.node, .dtree a.nodeSel {white-space: nowrap;padding: 1px 2px 1px 2px;}.dtree a.node:hover, .dtree a.nodeSel:hover {color: #333;text-decoration: underline;}.dtree a.nodeSel {background-color: #c0d2ec;}.dtree .clip {overflow: hidden;}

// Node objectfunction Node(id, pid, name, url, title, target, icon, iconOpen, open) {this.id = id;this.pid = pid;this.name = name;this.url = url;this.title = title;this.target = target;this.icon = icon;this.iconOpen = iconOpen;this._io = open || false;this._is = false;this._ls = false;this._hc = false;this._ai = 0;this._p;};// Tree objectfunction dTree(objName) {this.config = {target: null,folderLinks: true,useSelection: true,useCookies: true,useLines: true,useIcons: true,useStatusText: false,closeSameLevel: false,inOrder: false}this.icon = {root: 'img/base.gif',folder: 'img/folder.gif',folderOpen: 'img/folderopen.gif',node: 'img/page.gif',empty: 'img/empty.gif',line: 'img/line.gif',join: 'img/join.gif',joinBottom: 'img/joinbottom.gif',plus: 'img/plus.gif',plusBottom: 'img/plusbottom.gif',minus: 'img/minus.gif',minusBottom: 'img/minusbottom.gif',nlPlus: 'img/nolines_plus.gif',nlMinus: 'img/nolines_minus.gif'};this.obj = objName;this.aNodes = [];this.aIndent = [];this.root = new Node(-1);this.selectedNode = null;this.selectedFound = false;pleted = false;};// Adds a new node to the node arraydTree.prototype.add = function(id, pid, name, url, title, target, icon, iconOpen, open) {this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, title, target, icon, iconOpen, open);};// Open/close all nodesdTree.prototype.openAll = function() {this.oAll(true);};dTree.prototype.closeAll = function() {this.oAll(false);};// Outputs the tree to the pagedTree.prototype.toString = function() {var str = '<div class="dtree">\n';if (document.getElementById) {if (this.config.useCookies) this.selectedNode = this.getSelected();str += this.addNode(this.root);} else str += 'Browser not supported.';str += '</div>';if (!this.selectedFound) this.selectedNode = null;pleted = true;return str;};// Creates the tree structuredTree.prototype.addNode = function(pNode) {var str = '';var n=0;if (this.config.inOrder) n = pNode._ai;for (n; n<this.aNodes.length; n++) {if (this.aNodes[n].pid == pNode.id) {var cn = this.aNodes[n];cn._p = pNode;cn._ai = n;this.setCS(cn);if (!cn.target && this.config.target) cn.target = this.config.target;if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);if (!this.config.folderLinks && cn._hc) cn.url = null;if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {cn._is = true;this.selectedNode = n;this.selectedFound = true;}str += this.node(cn, n);if (cn._ls) break;}}return str;};// Creates the node icon, url and textdTree.prototype.node = function(node, nodeId) {var str = '<div class="dTreeNode">' + this.indent(node, nodeId);if (this.config.useIcons) {if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;if (this.root.id == node.pid) {node.icon = this.icon.root;node.iconOpen = this.icon.root;}str += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';}if (node.url) {str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"';if (node.title) str += ' title="' + node.title + '"';if (node.target) str += ' target="' + node.target + '"';if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ';if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';str += '>';}else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">';str += node.name;if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>';str += '</div>';if (node._hc) {str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';str += this.addNode(node);str += '</div>';}this.aIndent.pop();return str;};// Adds the empty and line iconsdTree.prototype.indent = function(node, nodeId) {var str = '';if (this.root.id != node.pid) {for (var n=0; n<this.aIndent.length; n++)str += '<img src="' + ( (this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty ) + '" alt="" />';(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);if (node._hc) {str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');"><img id="j' + this.obj + nodeId + '" src="';if (!this.config.useLines) str += (node._io) ? this.icon.nlMinus : this.icon.nlPlus;else str += ( (node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus ) );str += '" alt="" /></a>';} else str += '<img src="' + ( (this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join ) : this.icon.empty) + '" alt="" />';}return str;};// Checks if a node has any children and if it is the last siblingdTree.prototype.setCS = function(node) {var lastId;for (var n=0; n<this.aNodes.length; n++) {if (this.aNodes[n].pid == node.id) node._hc = true;if (this.aNodes[n].pid == node.pid) lastId = this.aNodes[n].id;}if (lastId==node.id) node._ls = true;};// Returns the selected nodedTree.prototype.getSelected = function() {var sn = this.getCookie('cs' + this.obj);return (sn) ? sn : null;};// Highlights the selected nodedTree.prototype.s = function(id) {if (!this.config.useSelection) return;var cn = this.aNodes[id];if (cn._hc && !this.config.folderLinks) return;if (this.selectedNode != id) {if (this.selectedNode || this.selectedNode==0) {eOld = document.getElementById("s" + this.obj + this.selectedNode);eOld.className = "node";}eNew = document.getElementById("s" + this.obj + id);eNew.className = "nodeSel";this.selectedNode = id;if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id);}};// Toggle Open or closedTree.prototype.o = function(id) {var cn = this.aNodes[id];this.nodeStatus(!cn._io, id, cn._ls);cn._io = !cn._io;if (this.config.closeSameLevel) this.closeLevel(cn);if (this.config.useCookies) this.updateCookie();};// Open or close all nodesdTree.prototype.oAll = function(status) {for (var n=0; n<this.aNodes.length; n++) {if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {this.nodeStatus(status, n, this.aNodes[n]._ls)this.aNodes[n]._io = status;}}if (this.config.useCookies) this.updateCookie();};// Opens the tree to a specific nodedTree.prototype.openTo = function(nId, bSelect, bFirst) {if (!bFirst) {for (var n=0; n<this.aNodes.length; n++) {if (this.aNodes[n].id == nId) {nId=n;break;}}}var cn=this.aNodes[nId];if (cn.pid==this.root.id || !cn._p) return;cn._io = true;cn._is = bSelect;if (pleted && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);if (pleted && bSelect) this.s(cn._ai);else if (bSelect) this._sn=cn._ai;this.openTo(cn._p._ai, false, true);};// Closes all nodes on the same level as certain nodedTree.prototype.closeLevel = function(node) {for (var n=0; n<this.aNodes.length; n++) {if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {this.nodeStatus(false, n, this.aNodes[n]._ls);this.aNodes[n]._io = false;this.closeAllChildren(this.aNodes[n]);}}}// Closes all children of a nodedTree.prototype.closeAllChildren = function(node) {for (var n=0; n<this.aNodes.length; n++) {if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);this.aNodes[n]._io = false;this.closeAllChildren(this.aNodes[n]);}}}// Change the status of a node(open or closed)dTree.prototype.nodeStatus = function(status, id, bottom) {eDiv= document.getElementById('d' + this.obj + id);eJoin= document.getElementById('j' + this.obj + id);if (this.config.useIcons) {eIcon= document.getElementById('i' + this.obj + id);eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;}eJoin.src = (this.config.useLines)?((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)):((status)?this.icon.nlMinus:this.icon.nlPlus);eDiv.style.display = (status) ? 'block': 'none';};// [Cookie] Clears a cookiedTree.prototype.clearCookie = function() {var now = new Date();var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);this.setCookie('co'+this.obj, 'cookieValue', yesterday);this.setCookie('cs'+this.obj, 'cookieValue', yesterday);};// [Cookie] Sets value in a cookiedTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {document.cookie =escape(cookieName) + '=' + escape(cookieValue)+ (expires ? '; expires=' + expires.toGMTString() : '')+ (path ? '; path=' + path : '')+ (domain ? '; domain=' + domain : '')+ (secure ? '; secure' : '');};// [Cookie] Gets a value from a cookiedTree.prototype.getCookie = function(cookieName) {var cookieValue = '';var posName = document.cookie.indexOf(escape(cookieName) + '=');if (posName != -1) {var posValue = posName + (escape(cookieName) + '=').length;var endPos = document.cookie.indexOf(';', posValue);if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));else cookieValue = unescape(document.cookie.substring(posValue));}return (cookieValue);};// [Cookie] Returns ids of open nodes as a stringdTree.prototype.updateCookie = function() {var str = '';for (var n=0; n<this.aNodes.length; n++) {if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {if (str) str += '.';str += this.aNodes[n].id;}}this.setCookie('co' + this.obj, str);};// [Cookie] Checks if a node id is in a cookiedTree.prototype.isOpen = function(id) {var aOpen = this.getCookie('co' + this.obj).split('.');for (var n=0; n<aOpen.length; n++)if (aOpen[n] == id) return true;return false;};// If Push and pop is not implemented by the browserif (!Array.prototype.push) {Array.prototype.push = function array_push() {for(var i=0;i<arguments.length;i++)this[this.length]=arguments[i];return this.length;}};if (!Array.prototype.pop) {Array.prototype.pop = function array_pop() {lastElement = this[this.length-1];this.length = Math.max(this.length-1,0);return lastElement;}};

实现截图

具体功能实现

查询所有表信息

jsp

<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><Body bgcolor=yellow><div align="center"><%@ include file="head.txt" %><FORM action="inquire.jsp" Method="post" > <br><br><br><br>输入表的名字: <Input type=text name="tableName" size=8> <Input type=submit name="g" value="提交"></Form></div></Font></Body></HTML>

inquirie.jsp

<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><Body bgcolor=cyan><Font size=2><div align="center"><% String tName=request.getParameter("tableName");%><inquire:Query tableName="<%=tName%>"/><%@ include file="head.txt" %><br><br><br><br>在<%=biao%>表查询到记录: <BR> <%=queryResult %> </div><div style="width:100%;text-align:center"><FORM action="inquire.jsp" Method="post" ><br><br>继续查询,请输入表的名字: <Input type=text name="tableName" size=8> <br><Input type=submit name="g" value="提交"></Form></div></Font></Body></HTML>

<%@ tag pageEncoding="GB2312" %><%@ tag import="java.sql.*" %><%@ attribute name="tableName" required="true" %> <%@ attribute name="password" required="false" %> <%@ variable name-given="biao" scope="AT_END" %><%@ variable name-given="queryResult" scope="AT_END" %><% StringBuffer result;result=new StringBuffer();try{ Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){} Connection con;Statement sql; ResultSet rs;try{ result.append("<table border=1>"); String uri="jdbc:mysql://127.0.0.1/"+"mobileshop";con=DriverManager.getConnection(uri,"root",password);DatabaseMetaData metadata=con.getMetaData();ResultSet rs1=metadata.getColumns(null,null,tableName,null);int 字段个数=0;result.append("<tr>");while(rs1.next()){字段个数++;String clumnName=rs1.getString(4);result.append("<td>"+clumnName+"</td>");}result.append("</tr>");sql=con.createStatement();rs=sql.executeQuery("SELECT * FROM "+tableName);while(rs.next()){result.append("<tr>");for(int k=1;k<=字段个数;k++) result.append("<td>"+rs.getString(k)+"</td>");result.append("</tr>");}result.append("</table>");con.close();}catch(SQLException e){result.append("请输入正确的用户名和密码");}//返回对象queryResult: jspContext.setAttribute("queryResult",new String(result)); jspContext.setAttribute("biao",tableName);//返回biao对象%>

修改用户信息

example6_8.jsp<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><BODY bgcolor=pink ><FONT size=2><div align="center"><FORM action="newResult2.jsp" method=post><table border=1><br><br>更新记录:<BR>输入被更新的记录的logname:<tr><td> 输入要更新的logname:</td><td><Input type="text" name="logname"></td></tr><tr><td>输入新的password:</td><td><Input type="text" name="password"></td></tr><tr><td>输入新的phone:</td><td><Input type="text" name="phone"></td></tr><tr><td>输入新的addess:</td><td><Input type="text" name="addess"></td></tr><tr><td>输入新的realname:</td><td><Input type="text" name="realname"></td></tr></table><BR><Input type="submit" name="b" value="提交更新"><BR><br><br>orderform表更新前的数据记录是:<inquire:Query tableName="user" /> <BR> <%=queryResult %></FORM></div></Font></BODY></HTML>

newresult2.jsp<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="renew"%><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><BODY bgcolor=pink><Font size=2><div align="center"><% String lo=request.getParameter("logname");String pa=request.getParameter("password");String ph=request.getParameter("phone");String ad=request.getParameter("addess");String re=request.getParameter("realname");byte bb[]=ad.getBytes("iso-8859-1");ad=new String(bb);byte aa[]=re.getBytes("iso-8859-1");re=new String(aa);%><renew:NewRecord2 logname="<%=lo%>" password="<%=pa%>" phone="<%=ph%>" addess="<%=ad%>"realname="<%=re%>"/> <BR>user表更新后的数据记录是:<inquire:Query tableName="user" /> <BR> <%=queryResult %></div></Font></BODY></HTML>

NewRecord2.tag<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><BODY bgcolor=pink ><FONT size=2><div align="center"><FORM action="newResult2.jsp" method=post><table border=1><br><br>更新记录:<BR>输入被更新的记录的logname:<tr><td> 输入要更新的logname:</td><td><Input type="text" name="logname"></td></tr><tr><td>输入新的password:</td><td><Input type="text" name="password"></td></tr><tr><td>输入新的phone:</td><td><Input type="text" name="phone"></td></tr><tr><td>输入新的addess:</td><td><Input type="text" name="addess"></td></tr><tr><td>输入新的realname:</td><td><Input type="text" name="realname"></td></tr></table><BR><Input type="submit" name="b" value="提交更新"><BR><br><br>orderform表更新前的数据记录是:<inquire:Query tableName="user" /> <BR> <%=queryResult %></FORM></div></Font></BODY></HTML>

删除用户信息

delete.jsp<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><BODY bgcolor=pink ><FONT size=2><div align="center"><FORM action="delete11.jsp" method=post><br><br><br><br>删除记录:<BR>输入被删除的记录的用户名:<Input type="text" name="logname" size=8><Input type="submit" name="b" value="提交"><BR><br>user表删除记录前的记录是:<inquire:Query tableName="user" /> <BR> <%=queryResult %> </FORM></div></Font></BODY></HTML>

delete11.jsp<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><BODY bgcolor=pink ><Font size=2><div align="center"><% String logname=request.getParameter("logname");if(logname==null)logname ="";byte [] bb=logname.getBytes("iso-8859-1");logname = new String(bb);%><inquire:DelRecord1 logname="<%=logname%>" /> <br><BR>user表删除记录后的记录是:<inquire:Query tableName="user" /> <BR> <%=queryResult %> </div></Font></BODY></HTML>

DelRecord1.tag<%@ tag pageEncoding="GB2312" %><%@ tag import="java.sql.*" %><%@ attribute name="logname" required="true" %><% String condition ="DELETE FROM user WHERE logname = '"+logname+"'";try{ Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){} Connection con;Statement sql; ResultSet rs;try{ String uri="jdbc:mysql://127.0.0.1/mobileshop?"+"user=root&password=&characterEncoding=gb2312";con=DriverManager.getConnection(uri);con=DriverManager.getConnection(uri,"root","");sql=con.createStatement();sql.executeUpdate(condition);con.close();}catch(Exception e){out.print(""+e);}%>

修改产品分类

example_9.jsp<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><BODY bgcolor=pink><FONT size=2><div align="center"><FORM action="newResult3.jsp" method=post><table border=1><br><br>更新记录:<BR>输入被更新的记录的id:<tr><td> 输入要更新的id:</td><td><Input type="text" name="id"></td></tr><tr><td>输入新的name:</td><td><Input type="text" name="name"></td></tr></table><BR><Input type="submit" name="b" value="提交更新"><BR>mobileclassify表更新前的数据记录是:<br><br><inquire:Query tableName="mobileclassify" /> <BR> <%=queryResult %></FORM></div></Font></BODY></HTML>

<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="renew"%><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><BODY bgcolor=pink><Font size=2><div align="center"><% String id=request.getParameter("id");String na=request.getParameter("name");byte aa[]=na.getBytes("iso-8859-1");na=new String(aa);%><renew:NewRecord3 id="<%=id%>" name="<%=na%>"/> <BR>mobileclassify表更新后的数据记录是:<inquire:Query tableName="mobileclassify" /> <BR> <%=queryResult %></div></Font></BODY></HTML>

NewRecord.tag

<%@ tag pageEncoding="GB2312" %><%@ tag import="java.sql.*" %><%@ attribute name="id" required="true" %><%@ attribute name="name" required="true" %><% //float p=Float.parseFloat(sum);String condition1="UPDATE mobileclassify SET name= '"+name+"' WHERE id="+"'"+id+"'" ; try{ Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){} Connection con;Statement sql; ResultSet rs;try{ String uri="jdbc:mysql://127.0.0.1/mobileshop?"+"user=root&password=&characterEncoding=gbk";con=DriverManager.getConnection(uri);sql=con.createStatement();sql.executeUpdate(condition1);con.close();}catch(Exception e){out.print(""+e);}%>

delete2.jsp<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><BODY bgcolor=pink ><FONT size=2><div align="center"><FORM action="delete22.jsp" method=post><br><br>删除记录:<BR>输入被删除的手机分类id:<Input type="text" name="logname" size=8><Input type="submit" name="b" value="提交"><BR><br><br>mobileclassify表删除记录前的记录是:<inquire:Query tableName="mobileclassify" /> <BR> <%=queryResult %> </FORM></div></Font></BODY></HTML>delete22.jsp<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><BODY bgcolor=pink ><Font size=2><% String logname=request.getParameter("logname");if(logname==null)logname ="";byte [] bb=logname.getBytes("iso-8859-1");logname = new String(bb);%><inquire:DelRecord2 logname="<%=logname%>" /> <BR>mobileclassify表删除记录后的记录是:<inquire:Query tableName="mobileclassify" /> <BR> <%=queryResult %> </Font></BODY></HTML>DelRecord.tag<%@ tag pageEncoding="GB2312" %><%@ tag import="java.sql.*" %><%@ attribute name="logname" required="true" %><% String condition ="DELETE FROM mobileclassify WHERE id = '"+logname+"'";try{ Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){} Connection con;Statement sql; ResultSet rs;try{ String uri="jdbc:mysql://127.0.0.1/mobileshop?"+"user=root&password=&characterEncoding=gb2312";con=DriverManager.getConnection(uri);con=DriverManager.getConnection(uri,"root","");sql=con.createStatement();sql.executeUpdate(condition);con.close();}catch(Exception e){out.print(""+e);}%>

修改订单

example6_7.jsp<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><BODY ><FONT size=2><div align="center"><FORM action="newResult.jsp" method=post><table border=1><br><br>更新记录:<BR>输入被更新的产品的id:<tr><td> 输入要更新的产品的id:</td><td><Input type="text" name="id"></td></tr><tr><td>输入新的logname:</td><td><Input type="text" name="logname"></td></tr><tr><td>输入新的mess:</td><td><Input type="text" name="mess"></td></tr><tr><td>输入新的sum:</td><td><Input type="text" name="sum"></td></tr></table><BR><Input type="submit" name="b" value="提交更新"><BR><br>orderform表更新前的数据记录是:<inquire:Query tableName="orderform" /> <br><%=queryResult %></FORM></div></Font></BODY></HTML>newResult.jsp<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="renew"%><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><BODY bgcolor=pink><Font size=2><div align="center"><% String nu=request.getParameter("id");String na=request.getParameter("logname");String mT=request.getParameter("mess");String pr=request.getParameter("sum");byte bb[]=na.getBytes("iso-8859-1");na=new String(bb);%><renew:NewRecord id="<%=nu%>" logname="<%=na%>" mess="<%=mT%>" sum="<%=pr%>"/> <BR>orderform表更新后的数据记录是:<inquire:Query tableName="orderform" /> <BR> <%=queryResult %></div></Font></BODY></HTML> NewRecord.tag<%@ tag pageEncoding="GB2312" %><%@ tag import="java.sql.*" %><%@ attribute name="id" required="true" %><%@ attribute name="logname" required="true" %><%@ attribute name="mess" required="true" %><%@ attribute name="sum" required="true" %><% float p=Float.parseFloat(sum);String condition1="UPDATE orderform SET logname= '"+logname+"' WHERE id="+"'"+id+"'" ,condition2="UPDATE orderform SET mess= '"+mess+"' WHERE id="+"'"+id+"'",condition3="UPDATE orderform SET sum= "+sum+" WHERE id="+"'"+id+"'" ;try{ Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){} Connection con;Statement sql; ResultSet rs;try{ String uri="jdbc:mysql://127.0.0.1/mobileshop?"+"user=root&password=&characterEncoding=gbk";con=DriverManager.getConnection(uri);sql=con.createStatement();sql.executeUpdate(condition1);sql.executeUpdate(condition2);sql.executeUpdate(condition3);con.close();}catch(Exception e){out.print(""+e);}%>

修改产品

删除

example6_10<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><BODY ><FONT size=2><div align="center"><FORM action="newResult4.jsp" method=post><table border=1><br><br>更新记录:<BR>输入被更新的记录的version:<tr><td> 输入要更新的version:</td><td><Input type="text" name="version"></td></tr><tr><td>输入新的name:</td><td><Input type="text" name="name"></td></tr><tr><td>输入新的made:</td><td><Input type="text" name="made"></td></tr><tr><td>输入新的price:</td><td><Input type="text" name="price"></td></tr><tr><td>输入新的mess:</td><td><Input type="text" name="mess"></td></tr><tr><td>输入新的pic:</td><td><Input type="text" name="pic"></td></tr></table><BR><Input type="submit" name="b" value="提交更新"><br><BR>mobileform表更新前的数据记录是:<inquire:Query tableName="mobileform" /> <BR> <%=queryResult %></FORM></div></Font></BODY></HTML>NewResult.jsp<%@ page contentType="text/html;charset=GB2312" %><%@ taglib tagdir="/WEB-INF/tags" prefix="renew"%><%@ taglib tagdir="/WEB-INF/tags" prefix="inquire"%><HTML><BODY bgcolor=pink><Font size=2><div align="center"><% String ve=request.getParameter("version");String na=request.getParameter("name");String ma=request.getParameter("made");String pr=request.getParameter("price");//String me=request.getParameter("mess");String pi=request.getParameter("pic");byte aa[]=na.getBytes("iso-8859-1");na=new String(aa);byte bb[]=ma.getBytes("iso-8859-1");ma=new String(bb);byte cc[]=me.getBytes("iso-8859-1");me=new String(cc);byte dd[]=pi.getBytes("iso-8859-1");pi=new String(dd);%><renew:NewRecord4 version="<%=ve%>" name="<%=na%>" made="<%=ma%>" price="<%=pr%>"mess="<%=me%>"pic="<%=pi%>"/> <BR>mobileform表更新后的数据记录是:<inquire:Query tableName="mobileform" /> <BR> <%=queryResult %></div></Font></BODY></HTML> NewRecord.tag<%@ tag pageEncoding="GB2312" %><%@ tag import="java.sql.*" %><%@ attribute name="version" required="true" %><%@ attribute name="name" required="true" %><%@ attribute name="made" required="true" %><%@ attribute name="price" required="true" %><%@ attribute name="mess" required="true" %><%@ attribute name="pic" required="true" %><% //float p=Float.parseFloat(sum);String condition1="UPDATE mobileform SET mobile_name= '"+name+"' WHERE mobile_version="+"'"+version+"'" ,condition2="UPDATE mobileform SET mobile_made= '"+made+"' WHERE mobile_version="+"'"+version+"'",condition3="UPDATE mobileform SET mobile_price= '"+price+"'WHERE mobile_version="+"'"+version+"'" ,condition4="UPDATE mobileform SET mobile_mess= '"+mess+"'WHERE mobile_version="+"'"+version+"'" ,condition5="UPDATE mobileform SET mobile_pic= '"+pic+"'WHERE mobile_version="+"'"+version+"'" ; try{ Class.forName("com.mysql.jdbc.Driver");}catch(Exception e){} Connection con;Statement sql; ResultSet rs;try{ String uri="jdbc:mysql://127.0.0.1/mobileshop?"+"user=root&password=&characterEncoding=gbk";con=DriverManager.getConnection(uri);sql=con.createStatement();sql.executeUpdate(condition1);sql.executeUpdate(condition2);sql.executeUpdate(condition3);sql.executeUpdate(condition4);sql.executeUpdate(condition5);con.close();}catch(Exception e){out.print(""+e);}%>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。