JSP:设计一个手机销售网页并实现后台管理功能

1前台页面

JSP:设计一个手机销售网页并实现后台管理功能_第1张图片

2.重要步骤

树形菜单的实现:

tree.jsp

<%@ page contentType="text/html;charset=GB2312" %>

后台管理

open all | close all

 

用户的添加

添加原理:userAdd.jsp提交新的记录到newUser.jsp页面,该页面调用AddUserRecord.tag文件添加新的记录到user表,从而实现user表的添加。

QueryTag.tag:别的页面通过提交数据库名,表名,用户名,密码可以浏览表的内容

<%@tag pageEncoding="GB2312"%>

<%@tag import="java.sql.*"%>

<%@attribute name="dataBaseName" required="true"%>

<%@attribute name="tableName" required="true"%>

<%@attribute name="user" 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){

result.append("请输入正确的用户名和密码");

}

Connection con;

Statement sql;

ResultSet rs;

try{ result.append("

");

       String uri="jdbc:mysql://127.0.0.1/"+dataBaseName;

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

      DatabaseMetaData metadata=con.getMetaData();

      ResultSet rs1=metadata.getColumns(null,null,tableName,null);

     int 字段个数=0;

     result.append("

");

    while(rs1.next()){

    字段个数++;

   String clumnName=rs1.getString(4);

   result.append("

");

   }

result.append("

");

sql=con.createStatement();

rs=sql.executeQuery("SELECT * FROM "+tableName);

  while(rs.next()){

result.append("

");

for(int k=1;k<=字段个数;k++)

result.append("

");

result.append("

");

}

result.append("

"+clumnName+"
"+rs.getString(k)+"
");

con.close();

}

catch(SQLException e){

result.append("请输入正确的用户名和密码");

}

jspContext.setAttribute("queryResult",new String(result));

jspContext.setAttribute("biao",tableName);

%>

userAdd.jsp

<%@page contentType="text/html;charset=gb2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

添加新纪录:

用户名:
密码:
电话:
邮箱地址:
真实名字:



user表添加新纪录之前的记录是:

                                tableName="user"

                              user="root" password="" />

   
<%=queryResult%>

返回主页

AddUserRecord.jsp

<%@tag pageEncoding="GB2312"%>

<%@tag import="java.sql.*"%>

<%@attribute name="logname" required="true"%>

<%@attribute name="password" required="true"%>

<%@attribute name="phone" required="true"%>

<%@attribute name="address" required="true"%>

<%@attribute name="realname" required="true"%>

<% String condition="INSERT INTO user VALUES"+

          "("+"'"+logname+"','"+password+"','"+phone+"','"+address+"','"+realname+"')";

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);

     sql=con.createStatement();

     sql.executeUpdate(condition);

     con.close();

 }

catch(Exception e){

   out.print(""+e);

}

%>

newUser.jsp

<%@page contentType="text/html;charset=gb2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

<%!

String handleStr(String s){

try{

byte bb[]=s.getBytes("iso-8859-1");

return new String(bb);

}

catch(Exception exp){}

return s;

}

%>

<% String log=handleStr(request.getParameter("logname"));

String pass=handleStr(request.getParameter("password"));

String ph=handleStr(request.getParameter("phone"));

String add=handleStr(request.getParameter("address"));

String real=handleStr(request.getParameter("realname"));

%>

                                  phone="<%=ph%>" address="<%=add%>" realname="<%=real%>" />


user表添加新记录后的记录是:

                                tableName="user"

                              user="root" password="" />

   
<%=queryResult%>


返回主页

AddUserRecord.tag

<%@tag pageEncoding="GB2312"%>

<%@tag import="java.sql.*"%>

<%@attribute name="logname" required="true"%>

<%@attribute name="password" required="true"%>

<%@attribute name="phone" required="true"%>

<%@attribute name="address" required="true"%>

<%@attribute name="realname" required="true"%>

<% String condition="INSERT INTO user VALUES"+

          "("+"'"+logname+"','"+password+"','"+phone+"','"+address+"','"+realname+"')";

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);

     sql=con.createStatement();

     sql.executeUpdate(condition);

     con.close();

 }

catch(Exception e){

   out.print(""+e);

}

%>

 

用户的删除

userDelete.jsp

<%@page contentType="text/html;charset=GB2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

删除记录:
输入您希望删除的用户名:



被删除前的用户表:

                               tableName="user"

                             user="root" password="" />


<%=queryResult%>

deleteUser.jsp

<%@page contentType="text/html;charset=gb2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

<% String na=request.getParameter("name");

       if(na==null)

        na="";

      byte []bb=na.getBytes("iso-8859-1");

       na=new String(bb);

%>


user表删除记录后:

                                tableName="user"

                              user="root" password="" />

   
<%=queryResult%>


返回主页

DelUserRecord.tag

<%@tag pageEncoding="GB2312"%>

<%@tag import="java.sql.*"%>

<%@attribute name="name" required="true"%>

<%String condition=

"DELETE FROM user WHERE logname= '"+name+"'";

try{ Class.forName("com.mysql.jdbc.Driver");

}

catch(Exception e){}

Connection con;

Statement sql;

ResultSet rs;

try{ String uri="jdbc:mysql://localhost/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);

}

%>

 

产品管理

添加产品

productAdd.jsp

<%@page contentType="text/html;charset=gb2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

添加新纪录:

 

手机编码:
手机名字:
生产公司:
手机价格:
手机特色:
手机图片:
序号:



mobileform表添加新纪录之前的记录是:

                                tableName="mobileform"

                              user="root" password="" />

   
<%=queryResult%>

newProduct.jsp

<%@page contentType="text/html;charset=gb2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

<%!

String handleStr(String s){

try{

byte bb[]=s.getBytes("iso-8859-1");

return new String(bb);

}

catch(Exception exp){}

return s;

}

%>

<% String version=handleStr(request.getParameter("mobile_version"));

String name=handleStr(request.getParameter("mobile_name"));

String made=handleStr(request.getParameter("mobile_made"));

String price=handleStr(request.getParameter("mobile_price"));

String mess=handleStr(request.getParameter("mobile_mess"));

String pic=handleStr(request.getParameter("mobile_pic"));

String id=handleStr(request.getParameter("id"));

%>

                                  mobile_made="<%=made%>" mobile_price="<%=price%>"

mobile_mess="<%=mess%>" mobile_pic="<%=pic%>"

                                    id="<%=id%>" />


mobile_form表添加新记录后的记录是:

                                tableName="mobileform"

                              user="root" password="" />

   
<%=queryResult%>


返回主页

AddProductRecord.tag

<%@tag pageEncoding="GB2312"%>

<%@tag import="java.sql.*"%>

<%@attribute name="mobile_version" required="true"%>

<%@attribute name="mobile_name" required="true"%>

<%@attribute name="mobile_made" required="true"%>

<%@attribute name="mobile_price" required="true"%>

<%@attribute name="mobile_mess" required="true"%>

<%@attribute name="mobile_pic" required="true"%>

<%@attribute name="id" required="true"%>

<%

  String condition="INSERT INTO mobileform VALUES"+

          "("+"'"+mobile_version+"','"+mobile_name+"','"+mobile_made+"','"+mobile_price+"','"+mobile_mess+"','"+mobile_pic+"','"+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=gb2312";

      con=DriverManager.getConnection(uri);

     sql=con.createStatement();

     sql.executeUpdate(condition);

     con.close();

 }

catch(Exception e){

   out.print(""+e);

}

%>

 

删除产品

productDelete.jsp

<%@page contentType="text/html;charset=GB2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

删除记录:
输入您希望删除的产品名称:



被删除前的产品表:

                               tableName="mobileform"

                             user="root" password="" />


<%=queryResult%>

deleteProduct.jsp

<%@page contentType="text/html;charset=gb2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

<% String na=request.getParameter("name");

       if(na==null)

        na="";

      byte []bb=na.getBytes("iso-8859-1");

       na=new String(bb);

%>


mobileform表删除记录后:

                                tableName="mobileform"

                              user="root" password="" />

   
<%=queryResult%>

 主页

DelProductRecord.tag

<%@tag pageEncoding="GB2312"%>

<%@tag import="java.sql.*"%>

<%@attribute name="name" required="true"%>

<%String condition=

"DELETE FROM mobileform WHERE mobile_name= '"+name+"'";

try{ Class.forName("com.mysql.jdbc.Driver");

}

catch(Exception e){}

Connection con;

Statement sql;

ResultSet rs;

try{ String uri="jdbc:mysql://localhost/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);

}

%>

 

分类管理

添加分类

classifyAdd.jsp

<%@page contentType="text/html;charset=gb2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

添加新纪录:

 

序号       :
分类类型:



分类表添加新纪录之前的记录是:

                                tableName="mobileClassify"

                              user="root" password="" />

   
<%=queryResult%>

newClassify.jsp

<%@page contentType="text/html;charset=gb2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

<%!

String handleStr(String s){

try{

byte bb[]=s.getBytes("iso-8859-1");

return new String(bb);

}

catch(Exception exp){}

return s;

}

%>

<% String identify=handleStr(request.getParameter("id"));

String na=handleStr(request.getParameter("name"));

%>


分类表添加新记录后的记录是:

                                tableName="mobileClassify

"

                              user="root" password="" />

   
<%=queryResult%>


返回主页

AddClassifyRecord.tag

<%@tag pageEncoding="GB2312"%>

<%@tag import="java.sql.*"%>

<%@attribute name="id" required="true"%>

<%@attribute name="name" required="true"%>

<% String condition="INSERT INTO mobileClassify VALUES"+

          "("+"'"+id+"','"+name+"')";

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);

     sql=con.createStatement();

     sql.executeUpdate(condition);

     con.close();

 }

catch(Exception e){

   out.print(""+e);

}

%>

删除分类

classifyDelete.jsp

<%@page contentType="text/html;charset=GB2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

删除记录:
输入您希望删除的分类的序号:



被删除前的分类表:

                               tableName="mobileClassify"

                             user="root" password="" />


<%=queryResult%>

deleteClassify.jsp

<%@page contentType="text/html;charset=gb2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

<% String identify=request.getParameter("id");

       if(identify==null)

        identify="";

      byte []bb=identify.getBytes("iso-8859-1");

       identify=new String(bb);

%>


分类表删除记录后:

                                tableName="mobileClassify"

                              user="root" password="" />

   
<%=queryResult%>

DelClassifyRecord.tag

<%@tag pageEncoding="GB2312"%>

<%@tag import="java.sql.*"%>

<%@attribute name="id" required="true"%>

<%String condition=

"DELETE FROM mobileClassify WHERE id= '"+id+"'";

try{ Class.forName("com.mysql.jdbc.Driver");

}

catch(Exception e){}

Connection con;

Statement sql;

ResultSet rs;

try{ String uri="jdbc:mysql://localhost/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);

}

%>

 

订单管理

添加订单

orderAdd.jsp

<%@page contentType="text/html;charset=gb2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

添加新纪录:

序号:
消费者用户名:
消费事项:
消费总额:



orderform表添加新纪录之前的记录是:

                                tableName="orderform"

                              user="root" password="" />

   
<%=queryResult%>

newOrder.jsp

<%@page contentType="text/html;charset=gb2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

<%!

String handleStr(String s){

try{

byte bb[]=s.getBytes("iso-8859-1");

return new String(bb);

}

catch(Exception exp){}

return s;

}

%>

<% String id=handleStr(request.getParameter("id"));

String log=handleStr(request.getParameter("logname"));

String mes=handleStr(request.getParameter("mess"));

String su=handleStr(request.getParameter("sum"));

%>

                                  mess="<%=mes%>"  sum="<%=su%>" />


orderform表添加新记录后的记录是:

                                tableName="orderform"

                              user="root" password="" />

   
<%=queryResult%>


返回主页

AddOrderRecord.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"%>

<%

  String condition="INSERT INTO orderform VALUES"+

          "("+"'"+id+"','"+logname+"','"+mess+"','"+sum+"')";

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);

     sql=con.createStatement();

     sql.executeUpdate(condition);

     con.close();

 }

catch(Exception e){

   out.print(""+e);

}

%>

 

删除订单

orderDelete.jsp

<%@page contentType="text/html;charset=GB2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

删除记录:
输入您希望删除的订单的消费者名称:



被删除前的订单表:

                               tableName="orderform"

                             user="root" password="" />


<%=queryResult%>

deleteOrder.jsp

<%@page contentType="text/html;charset=gb2312"%>

<%@taglib tagdir="/WEB-INF/tags" prefix="inquire"%>

<% String na=request.getParameter("name");

       if(na==null)

        na="";

      byte []bb=na.getBytes("iso-8859-1");

       na=new String(bb);

%>


orderform表删除记录后:

                                tableName="orderform"

                              user="root" password="" />

   
<%=queryResult%>

DelOrderRecord.tag

<%@tag pageEncoding="GB2312"%>

<%@tag import="java.sql.*"%>

<%@attribute name="name" required="true"%>

<%String condition=

"DELETE FROM orderform WHERE logname= '"+name+"'";

try{ Class.forName("com.mysql.jdbc.Driver");

}

catch(Exception e){}

Connection con;

Statement sql;

ResultSet rs;

try{ String uri="jdbc:mysql://localhost/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);

}

%>

 

 

 

你可能感兴趣的:(JSP:设计一个手机销售网页并实现后台管理功能)