Web实验报告
班级:信管1172 学号:201711671231 姓名:姚思敏
功能说明
(一)用户端
一、主页
二、注册
三、登录
四、浏览手机
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="mybean.data.DataByPage" %>
<%@ page import="com.sun.rowset.*" %>
<%@ include file="head.txt" %>
当前显示的内容是:
手机标识号
手机名称
手机制造商
手机价格
查看详情
添加到购物车
<%
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;//总页数
else
totalPages = 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="";
String detail="";
out.print("");
out.print(""+number+" ");
out.print(""+name+" ");
out.print(""+maker+" ");
out.print(""+price+" ");
out.print(""+detail+" ");
out.print(""+button+" ");
out.print(" ");
boo=rowSet.next();
}
}
%>
每页最多显示 条信息
当前显示第
页,共有
页。
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%@ include file="head.txt" %>
首页
欢迎光临“智多星”智能手机销售网
<%@ page contentType="text/html;charset=GB2312" %>
<%@ include file="head.txt" %>
注册页面
注册反馈:
会员名称:
姓名:
地址:
电话:
<%@ page contentType="text/html;charset=GB2312" %>
<%@ include file="head.txt" %>
登录
登录反馈信息:
登录名称:
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<%@ include file="head.txt" %>
选择某类手机
分页显示这类手机
<% try { Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e){}
String uri="jdbc:mysql://127.0.0.1/mobileshop?"+
"user=root&password=123&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("");
con.close();
}
catch(SQLException e){
out.print(e);
}
%>
<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.sql.*" %>
<%@ include file="head.txt" %>
<% 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="123";
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("");
out.print("");
out.print(""+"订单号");
out.print(" "+"信息");
out.print(" "+"价格");
out.print(" ");
while(rs.next()){
out.print("");
out.print(""+rs.getString(1)+" ");
out.print(""+rs.getString(2)+" ");
out.print(""+rs.getString(3)+" ");
out.print(" ") ;
}
out.print("
");
con.close();
}
catch(SQLException e){
out.print(e);
}
%>