1前台页面
2.重要步骤
树形菜单的实现:
tree.jsp
<%@ page contentType="text/html;charset=GB2312" %>
后台管理
d = new dTree('d');
d.add(0,-1,'后台管理系统');
d.add(1,0,'用户管理');
d.add(2,1,'添加用户');
d.add(3,1,'删除用户');
d.add(5,0,'产品管理');
d.add(6,5,'添加产品');
d.add(7,5,'删除产品');
d.add(9,0,'产品分类');
d.add(10,9,'添加类型');
d.add(11,9,'删除类型');
d.add(13,0,'订单管理');
d.add(14,13,'添加订单');
d.add(15,13,'删除订单');
d.add(17,0,'返回主页');
document.write(d);
用户的添加
添加原理: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("
"+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"%>
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%>" /> tableName="user" user="root" password="" />
user表添加新记录后的记录是:
<%=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"%>
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"%>
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%>" /> tableName="mobileform" user="root" password="" />
mobile_form表添加新记录后的记录是:
<%=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"%>
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"%>
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"%>
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"%>
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%>" /> tableName="orderform" user="root" password="" />
orderform表添加新记录后的记录是:
<%=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"%>
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);
}
%>