《JSP程序设计》手机销售网后台设计
本次实验设计以《JSP程序设计》课本第十章的例子项目为基础进行设计添加后台功能,后台页面分成左右两个框,左边显示一个树形菜单,右边根据菜单选择显示相应的交互界面。以实现对用户,产品分类,产品,订单等的后台管理。
一、前期工作
安装myeclipse10,将课本第十章的例子项目导入软件并调试好相关环境,保证项目的正常运行使用。所有的页面包括一个导航条,导航条由注册、登录、浏览手机、查看订单功能。
检测各功能的正常使用
二、后台设计与实验
首先在导航栏添加后台链接选项
在dtree官网下载dtree菜单源码,对源码更改实现具体功能,后台页面实现功能如下:
设计登录验证,只有管理员登录后才能进去后台管理界面,管理员数据库表如图,
登录验证代码如下:
rootlogin.jsp
<%@ page contentType="text/html;charset=GB2312" %>
<jsp:useBean id="login" class="mybean.data.rootlogin" scope="session"/>
<html>
<style>
table { border-collapse:collapse; }
</style>
<body bgcolor=pink>
<font size=3>
<p align="center"><b>管理员登录</b></p>
<div align="center">
<a href =index.jsp>返回主页 </a>
<a href =goDtree.jsp> 管理界面</a>
<br/><br/>
<table border=2>
<tr> <th>登录</th></tr>
<form action="rootlogin" Method="post">
<tr><td>登录名称:<Input type=text name="logname"></td></tr>
<tr><td>输入密码:<Input type=password name="password"></td></tr>
</table>
<br/><Input type=submit name="g" value="登录">
</form>
</div >
<div align="center" >
<br/>登录反馈信息:
<jsp:getProperty name="login" property="backNews"/>
<br/><br/>登录名称: <jsp:getProperty name="login" property="logname"/>
<br/>
<div >
</font>
</body></html>
rootlogin.jsp使用的Java Servlet代码如下:
rootLogin.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 rootLogin 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=123&characterEncoding=gb2312";
boolean boo=(logname.length()>0)&&(password.length()>0);
try{
con=DriverManager.getConnection(uri);
String condition="select * from rootuser 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("rootlogin.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) {
rootlogin login=null;
HttpSession session=request.getSession(true);
try{ login=(rootlogin)session.getAttribute("login");
if(login==null){
login=new rootlogin(); //创建新的数据模型
session.setAttribute("login",login);
login=(rootlogin)session.getAttribute("login");
}
String name =login.getLogname();
if(name.equals(logname)) {
login.setBackNews(logname+" 管理员已经登录了");
login.setLogname(logname);
}
else { //数据模型存储新的登录用户
login.setBackNews(logname+" 管理员登录成功");
login.setLogname(logname);
}
}
catch(Exception ee){
login=new rootlogin();
session.setAttribute("login",login);
login.setBackNews(logname+"登录成功");
login.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><a href =rootlogin.jsp>返回登录界面</a>");
out.println("<br><a href =index.jsp>返回主页</a>");
out.println("</body></html>");
}
catch(IOException exp){}
}
}
在管理员登录后可点击验证界面的两个选项中的后台管理进去后台管理,或者回到主页进行浏览。
后台界面采用dtree菜单形式,左边是树形菜单,右边是点击菜单的操作界面
houtai.jsp
<%@ page language=“java” import=“java.util.*” pageEncoding=“gb2312”%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="StyleSheet" href="dtree.css" type="text/css" />
<script type="text/javascript" src="dtree.js"></script>
手机销售网后台管理
<div id="left" >
<!-- <h2>菜单</h2> -->
<a target=_top href=houtai.jsp><h2>菜单</h2></a>
<a target=_top href=index.jsp><button><b>返回主页</b></button></a>
<a target=_top href=exitMana><button><b>退出管理</b></button></a>
<p><a href="javascript: d.openAll();">展开菜单</a> | <a href="javascript: d.closeAll();">收起菜单</a></p>
<script type="text/javascript">
d = new dTree('d');
d.add(0,-1,'管理菜单');
d.add(1,0,'用户管理');
d.add(2,1,'浏览用户','scanUser.jsp');
d.add(3,1,'查询用户','findUser.jsp');
d.add(4,1,'增加用户','addUser.jsp');
d.add(5,1,'修改用户','modifyUser.jsp');
d.add(6,1,'删除用户','deleUser.jsp');
d.add(7,0,'订单管理');
d.add(8,7,'浏览订单','scanOrderForm.jsp');
d.add(9,7,'查询订单','findOrderForm.jsp');
d.add(10,7,'修改订单','modifyOrderForm.jsp');
d.add(11,7,'删除订单','deleOrderForm.jsp');
d.add(12,0,'手机管理');
d.add(13,12,'增加手机','addMobile.jsp');
d.add(14,12,'修改手机','modifyMobile.jsp');
d.add(15,12,'删除手机','deleMobile.jsp');
document.write(d);
</script>
</div>
<!-- 右侧 -->
<div id="right">
<iframe frameboder="0" border="0" scrolling="no" name="iframe" src="" width="828" height=585></iframe>
</div>
后台左侧的菜单除了一些树形菜单功能外,还设置了三个功能键,返回主页键用以返回主页、“菜单”清空右侧页面并刷新以及退出管理员的登录管理并返回主页。
接下来是对各个子功能的实现。
(1)用户管理
浏览用户
管理员可对整个网站的用户进行浏览。
scanUser.jsp
<%@ page contentType=“text/html;charset=GB2312” %>
<%@ page import=“mybean.data.QueryBean” %>
<jsp:useBean id=“base” class=“mybean.data.QueryBean” scope=“page”/>
<jsp:setProperty name=“base” property=“databaseName” value=“mobileshop”/>
<jsp:setProperty name=“base” property=“tableName” value=“user”/>
<jsp:setProperty name=“base” property=“user” value=“root”/>
<jsp:setProperty name=“base” property=“password” value=“123”/>
当前网站的所有用户如下:
<jsp:getProperty name=“base” property=“queryResult”/>
辅助scanUser.jsp页面进行浏览的Java Bean
QueryBean.java
package mybean.data;
import java.sql.*;
public class QueryBean{
String databaseName=""; //数据库名
String tableName=""; //表名
String user="" ; //用户
String password="" ; //密码
StringBuffer queryResult; //查询结果
public QueryBean(){
queryResult=new StringBuffer();
try{ Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e) {}
}
public void setDatabaseName(String s){
databaseName=s.trim();
queryResult=new StringBuffer();
}
public String getDatabaseName(){
return databaseName;
}
public void setTableName(String s){
tableName=s.trim();
queryResult=new StringBuffer();
}
public String getTableName(){
return tableName;
}
public void setPassword(String s){
password=s.trim();
queryResult=new StringBuffer();
}
public String getPassword(){
return password;
}
public void setUser(String s){
user=s.trim();
queryResult=new StringBuffer();
}
public String getUser(){
return user;
}
public StringBuffer getQueryResult(){
Connection con;
Statement sql;
ResultSet rs;
try{ queryResult.append("<table border=1>");
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;
queryResult.append("<tr>");
while(rs1.next()){
字段个数++;
String clumnName=rs1.getString(4);
queryResult.append("<td>"+clumnName+"</td>");
}
queryResult.append("</tr>");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM "+tableName);
while(rs.next()){
queryResult.append("<tr>");
for(int k=1;k<=字段个数;k++)
queryResult.append("<td>"+rs.getString(k)+"</td>");
queryResult.append("</tr>");
}
queryResult.append("</table>");
con.close();
}
catch(SQLException e){
queryResult.append("请输入正确的用户名和密码");
}
return queryResult;
}
}
查询用户功能
在此功能,管理员可选择根据用户真实名字或网站会员名进行查找,考虑到网站会员名是唯一,但真实名字可不唯一,所以在查询的结果上实现了分页显示。
findUser.jsp
<%@ page contentType=“text/html;charset=GB2312” %>
输入查询信息:
用户名字
真实名字
辅助findUser.jsp进行查询的Java Servlet
FindUser.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 FindUser 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("logname")) {
condition =
"SELECT * FROM user where logname LIKE '%"+searchMess+"%'";
}
if(radioMess.equals("realname")) {
condition =
"SELECT * FROM user where realname LIKE '%"+searchMess+"%'";
}
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=123&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("userPageShow.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("<a href =findUser.jsp>返回继续查找用户</a>");
out.println("</body></html>");
}
catch(IOException exp){}
}
}
增加用户功能
考虑到若是网站用户因某些特殊原因无法注册时,可寻求管理员代为注册,所以选择了增加此功能。此功能与网站前段的注册页面类似。
addUser.jsp
<%@ page contentType=“text/html;charset=GB2312” %>
<jsp:useBean id=“user” class=“mybean.data.UserAdd” scope=“request”/>
用户名由字母、数字、下划线构成,*注释项为必填项。
添加结果:
<jsp:getProperty name=“user” property=“backNews” />
<tr>
<td> 会员名称 </td><td> 登录密码 </td><td> 真实姓名 </td><td> 联系地址 </td><td> 联系电话 </td>
</tr>
<tr>
<td><jsp:getProperty name="user" property="logname"/></td>
<td><jsp:getProperty name="user" property="password"/></td>
<td><jsp:getProperty name="user" property="realname"/></td>
<td><jsp:getProperty name="user" property="address"/></td>
<td><jsp:getProperty name="user" property="phone"/></td>
</tr>
UserAdd.java
package mybean.data;
public class UserAdd {
String logname="" , phone="", password="",
address="",realname="",backNews="请输入信息";
public String getLogname() {
return logname;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setLogname(String logname) {
this.logname = logname;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getRealname() {
return realname;
}
public void setRealname(String realname) {
this.realname = realname;
}
public String getBackNews() {
return backNews;
}
public void setBackNews(String backNews) {
this.backNews = backNews;
}
}
增加用户addUser.jsp使用的Java Servlet
AddUser.java
package myservlet.control;
import mybean.data.*;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class AddUser 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=123&characterEncoding=gb2312";
Connection con;
PreparedStatement sql;
UserAdd user=new UserAdd(); //创建的Javabean模型
request.setAttribute("user",user);
String logname=request.getParameter("logname").trim();
String password=request.getParameter("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="";
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="添加成功";
user.setBackNews(backNews);
user.setLogname(logname);
user.setPassword(handleString(password));
user.setPhone(handleString(phone));
user.setAddress(handleString(address));
user.setRealname(handleString(realname));
}
}
else {
backNews="信息填写不完整或名字中有非法字符";
user.setBackNews(backNews);
}
con.close();
}
catch(SQLException exp){
backNews="该会员名已存在,请更换名字"+exp;
user.setBackNews(backNews);
}
RequestDispatcher dispatcher=
request.getRequestDispatcher("addUser.jsp");
dispatcher.forward(request, response);//转发
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException {
doPost(request,response);
}
}
修改用户
当因为某些需求时,管理员实现对用户的信息修改,本界面可实时观看用户数据修改的变化,输入信息再提交前可看到修改前的用户数据列表,提交修改后数据表实时动态更新。
changeUser.jsp
<%@ page contentType=“text/html;charset=GB2312” %>
<%@ page import=“mybean.data.*” %>
<jsp:useBean id=“base” class=“mybean.data.QueryBean” scope=“page”/>
<jsp:setProperty name=“base” property=“databaseName” value=“mobileshop”/>
<jsp:setProperty name=“base” property=“tableName” value=“user”/>
<jsp:setProperty name=“base” property=“user” value=“root”/>
<jsp:setProperty name=“base” property=“password” value=“123”/>
<%@ page contentType=“text/html;charset=GB2312” %>
<jsp:useBean id=“user” class=“mybean.data.changeuser” scope=“request”/>
用户表更新数据记录:
<jsp:getProperty name=“base” property=“queryResult”/>
修改用户信息页面使用的 Java Servlet
changeUser.java
package myservlet.control;
import mybean.data.*;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class changeUser 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=123&characterEncoding=gb2312";
Connection con;
Statement sql;
ResultSet rs;
changeuser userBean=new changeuser(); //创建的Javabean模型
request.setAttribute("userBean",userBean);
String logname=request.getParameter("logname").trim();
String newlogname=request.getParameter("newlogname").trim();
String newpassword=request.getParameter("newpassword").trim();
String newphone=request.getParameter("newphone").trim();
String newaddress=request.getParameter("newaddress").trim();
String newrealname=request.getParameter("newrealname").trim();
byte a[]=logname.getBytes("ISO-8859-1");
logname=new String(a);
byte b[]=newlogname.getBytes("ISO-8859-1");
newlogname=new String(b);
byte c[]=newpassword.getBytes("ISO-8859-1");
newpassword=new String(c);
byte d[]=newphone.getBytes("ISO-8859-1");
newphone=new String(d);
byte e[]=newaddress.getBytes("ISO-8859-1");
newaddress=new String(e);
byte f[]=newrealname.getBytes("ISO-8859-1");
newrealname=new String(f);
if(logname==null)
logname="";
if(newlogname==null)
newlogname="";
String backNews="";
try{ con=DriverManager.getConnection(uri);
String Condition1="update user set logname='"+newlogname+"'where logname="+"'"+logname+"'",
Condition2="update user set password='"+newpassword+"'where logname="+"'"+logname+"'",
Condition3="update user set phone='"+newphone+"'where logname="+"'"+logname+"'",
Condition4="update user set address='"+newaddress+"'where logname="+"'"+logname+"'",
Condition5="update user set realname='"+newrealname+"'where logname="+"'"+logname+"'";
sql=con.createStatement();
sql.executeUpdate(Condition1);
sql.executeUpdate(Condition2);
sql.executeUpdate(Condition3);
sql.executeUpdate(Condition4);
sql.executeUpdate(Condition5);
int m1=sql.executeUpdate(Condition1);
if(m1!=0){
backNews="修改成功";
userBean.setBackNews(backNews);
userBean.setLogname(logname);
userBean.setNewlogname(newlogname);
userBean.setNewphone(handleString(newphone));
userBean.setNewaddress(handleString(newaddress));
userBean.setNewrealname(handleString(newrealname));
}
else {
backNews="信息填写不完整或名字中有非法字符";
userBean.setBackNews(backNews);
}
con.close();
}
catch(SQLException exp){
backNews="该会员名已存在,请更换名字"+exp;
userBean.setBackNews(backNews);
}
RequestDispatcher dispatcher=
request.getRequestDispatcher("changeUser.jsp");
dispatcher.forward(request, response);//转发
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException {
doPost(request,response);
}
}
修改用户页面使用的Java Bean
changeuser.java
package mybean.data;
public class changeuser {
String logname="" , newlogname="",newphone="", newpassword="",
newaddress="",newrealname="",backNews="请输入信息";
public String getLogname() {
return logname;
}
public void setLogname(String logname) {
this.logname = logname;
}
public String getNewlogname() {
return newlogname;
}
public void setNewlogname(String newlogname) {
this.newlogname = newlogname;
}
public String getNewphone() {
return newphone;
}
public void setNewphone(String newphone) {
this.newphone = newphone;
}
public String getNewpassword() {
return newpassword;
}
public void setNewpassword(String newpassword) {
this.newpassword = newpassword;
}
public String getNewaddress() {
return newaddress;
}
public void setNewaddress(String newaddress) {
this.newaddress = newaddress;
}
public String getNewrealname() {
return newrealname;
}
public void setNewrealname(String newrealname) {
this.newrealname = newrealname;
}
public String getBackNews() {
return backNews;
}
public void setBackNews(String backNews) {
this.backNews = backNews;
}
}
删除用户
对本网站的用户进行删除,以用户名称为关键字进行删除,信息的变动可实时显示。
deleteUser.jsp
<%@ page contentType=“text/html;charset=GB2312” %>
<%@ page import=“mybean.data.*” %>
<jsp:useBean id=“base” class=“mybean.data.QueryBean” scope=“page”/>
<jsp:setProperty name=“base” property=“databaseName” value=“mobileshop”/>
<jsp:setProperty name=“base” property=“tableName” value=“user”/>
<jsp:setProperty name=“base” property=“user” value=“root”/>
<jsp:setProperty name=“base” property=“password” value=“123”/>
<%@ page contentType=“text/html;charset=GB2312” %>
<jsp:useBean id=“user” class=“mybean.data.deleteuser” scope=“request”/>
用户表数据变动显示:
<jsp:getProperty name=“base” property=“queryResult”/>
删除界面使用的Java Bean
deleteuser.java
package mybean.data;
public class deleteuser {
String logname;
public String getLogname() {
return logname;
}
public void setLogname(String logname) {
this.logname = logname;
}
public String getBackNews() {
return backNews;
}
public void setBackNews(String backNews) {
this.backNews = backNews;
}
String backNews="请输入信息";
}
删除页面使用的Java Servlet
DeleteUser.java
package myservlet.control;
import mybean.data.*;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DeleteUser 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=123&characterEncoding=gb2312";
Connection con;
Statement sql;
ResultSet rs;
changeuser userBean=new changeuser(); //创建的Javabean模型
request.setAttribute("userBean",userBean);
String logname=request.getParameter("logname").trim();
byte a[]=logname.getBytes("ISO-8859-1");
logname=new String(a);
if(logname==null)
logname="";
String backNews="";
try{ con=DriverManager.getConnection(uri);
String Condition1="delete from user where logname="+"'"+logname+"'";
sql=con.createStatement();
sql.executeUpdate(Condition1);
int m1=sql.executeUpdate(Condition1);
if(m1!=0){
backNews="删除成功";
userBean.setBackNews(backNews);
userBean.setLogname(logname);
}
else {
backNews="用户名不存在";
userBean.setBackNews(backNews);
}
con.close();
}
catch(SQLException exp){
backNews="该会员名不存在"+exp;
userBean.setBackNews(backNews);
}
RequestDispatcher dispatcher=
request.getRequestDispatcher("deleteUser.jsp");
dispatcher.forward(request, response);//转发
}
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException {
doPost(request,response);
}
}
(2)订单管理
浏览订单
实现对当前网站的所有订单浏览,实现原理同浏览用户。
查询订单
用户可选择根据订单序号或者订单的用户名进行查询,实现原理同浏览用户。
删除订单
在删除文本框输入订单序号进行删除,实现原理与前面的删除用户相同。
(3)手机管理
增加手机分类
实现原理如前面增加用户。
修改手机分类
实现原理同修改用户
删除手机分类以及删除手机原理也同前面一样,不再展示。
未完成功能:
订单的增加以及修改
手机产品的增加及修改
实验总结
在实现后台管理界面的要求上未能达到要求,基本完成了一个功能模块,其他模块的相同功能的代码都基本一致。整个实验代码有待完善,实验中的一些未完成的功能仍需后续完成,以及可能存在的一些bug未全部排查完毕,代码技术含量较低。