一个简单的web项目 mysql_一个简单的java web 项目

本文实现一个简单的 java web 项目,包括以下5个功能:

1. 登录

用户默认主页index.jsp , 可选择登录功能,输入用户名和密码,若登录成功,则进入产品管理总页面main.jsp。若不成功仍退回index.jsp

bfe95cb45893168913884c67ff5c9731.png

2. 注册

用户默认主页index.jsp ,  可选择注册功能 ,若注册,则进入 register.jsp

1a03de66a13f3443dff1eead23468de5.png

3. 管理产品(增加,删除,查看)

登录成功后,进入产品管理总页面main.jsp。第一次进入main.jsp,默认显示所有产品列表。在此页面上更实现 查询某个产品记录,添加产品,批量删除,选中一项产品查看详情,实现分页功能。

d6faecda93722198ff25677c01bd9766.png

3.1 添加产品

02da0c369752fd7666f52ba303dc56fa.png

3.2 查询"圣女果"

33337ef20c20fd342a8893826ef1b80c.png

3.3 选择“香蕉” ,点击 “查看”

68938d170ca53165f5dce0ce8a95f231.png

4. 退出

用户点击“退出”时,清除session,退回主页面index.jsp

e138dac4ce54226ea78bcecd6c5c2241.png

5. 过滤器

若用户没有登录成功,而直接访问 main.jsp 或 addProduct.jsp ,则被过滤器过滤到 index.jsp . 因为有成功登录,验证其身份后,才有权利访问产品和管理产品。否则将被过滤到默认主页index.jsp.

例如:在地址栏直接输入:http://192.168.0.103:8080/xianfengProject/main.jsp,则被过滤到index.jsp

e138dac4ce54226ea78bcecd6c5c2241.png

-------------------------------------------------------------------------------

项目环境:

操作系统:win7

实现技术:jsp+servlet

数据库: mysql5.5.20 , Navicat_for_MySQL_11.0.10

服务器:apache-tomcat-7.0.40

开发平台: MyEclipse10

--------------------------------------------------------------------------------

说明:

1. 数据库

数据库名:mydb , 共两张表.

表一:userinfo (id , username , pswd)

表二:product (proid , proname, proprice , proaddress , proimage)

ef6e70c5531a0d08f280bd62aeab0d8d.png

product (proid , proname, proprice , proaddress , proimage)表结构:

05ba39f78031cd9ef8464d1a3634ae0e.png

userinfo (id , username , pswd)表结构如下:

3ca93ae68c9b3ca9dbab203db9627b34.png

2. MyEclipse 工程目录

1fc914e9eca054da3036294e672497df.png  

76de3d09ac398e2f8982a09d7c3b74be.png

----------------------------------------------------------------------------------------------------------------------

1. index.jsp

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

先锋管理系统欢迎您

var th = document.form1;

if(th.username.value==""){

alert("用户名不能为空!");

th.username.focus();

return;

}

if(th.pswd.value==""){

alert("密码不能为空!");

th.pswd.focus();

return;

}

th.action = "<%=path%>/servlet/LoginAction";

th.submit();

}

先锋管理系统欢迎你!

用户名:
密码:

登录

注册

2. register.jsp

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

注册新用户

var th = document.form1;

if(th.username.value==""){

alert("用户名不能为空!");

th.username.focus();

return;

}

if(th.pswd.value==""){

alert("密码不能为空!");

th.pswd.focus();

return;

}

th.action="<%=path%>/servlet/RegisterAction";

th.submit();

}

function back(){

alert("退回主页!");

th = document.form1;

th.acton="<%=path%>/index.jsp";

th.submit;

}

用户注册

用户名: 必须填写!
密 码: 必须填写!

确定

返回

3.main.jsp

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

//获取 session 中的 username;

String username = (String)session.getAttribute("username");

//获取从 servlet ProductActiion 中 传递的参数(数据库查询的结果)

List> list =(List>) request.getAttribute("listProduct");

// 获取 分页对象

DividePage dividePage = (DividePage) request.getAttribute("dividePage");

// 获取查询的关键词

String productName = (String) request.getAttribute("productName");

if(list==null){

//第一次进 main.jsp页面,默认加载所有的产品

ProductService service = new ProductDao();

int totalRecord = service.getItemCount("");

dividePage = new DividePage(5,totalRecord,1);

int start = dividePage.fromIndex();

int end = dividePage.toIndex();

list = service.listProduct("", start, end);

}

%>

产品管理

var th = document.form2;

th.action="<%=path%>/servlet/ProductAction?action_flag=search";

th.submit();

}

function first(){

window.location.href = "<%=path%>/servlet/ProductAction?action_flag=search&pageNum=1";

}

function next(){

window.location.href = "<%=path%>/servlet/ProductAction?action_flag=search&pageNum=<%=dividePage.getCurrentPage()+1%>";

}

function forward(){

window.location.href = "<%=path%>/servlet/ProductAction?action_flag=search&pageNum=<%=dividePage.getCurrentPage()-1%>";

}

function end(){

window.location.href = "<%=path%>/servlet/ProductAction?action_flag=search&pageNum=<%=dividePage.getPageCount() %>";

}

function changePage(currentPage){

window.location.href = "<%=path%>/servlet/ProductAction?action_flag=search&pageNum="+currentPage;

}

function selectAll(flag){

var ids = document.getElementsByName("ids");

for(var i = 0 ; i < ids.length ; i++){

ids[i].checked = flag;

}

}

function getSelectedCount(){

var ids = document.getElementsByName("ids");

var count = 0;

for(var i = 0 ; i < ids.length ; i++)

{

ids[i].checked==true?count++:0;

}

return count;

}

function del(){

if(getSelectedCount()==0){

alert("至少选择一个删除项!");

return;

}

var th = document.form1;

th.action="<%=path%>/servlet/ProductAction?action_flag=del";

th.submit();

}

function getSelectedValue(){

var ids = document.getElementsByName("ids");

for(var i = 0 ; i < ids.length ; i++)

{

if(ids[i].checked){

return ids[i].value;

}

}

}

function view(){

if(getSelectedCount()<1){

alert("至少选择一个查看项!");

return;

}else if(getSelectedCount()>1){

alert("只能选择一个查看项!");

return;

}

var th = document.form1;

th.action="<%=path%>/servlet/ProductAction?action_flag=view&proid="+getSelectedValue();

th.submit();

}

function logout(){

window.location.href="<%=path %>/servlet/LogoutAction?action_flag=logout";

}

欢迎您的光临,退出
产品信息查询
产品名称 "/>

查询

添加

查询结果
产品名称 产品产地 产品价格

if(list!=null && !list.isEmpty()){

for(Map map :list){%>

"/>

}else{%>

}

%></

  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值