标签:rda pack web.xml 限制 mysql5.5 declared gis error order
本文实现一个简单的 java web 项目,包括以下5个功能:
1. 登录
用户默认主页index.jsp , 可选择登录功能,输入用户名和密码,若登录成功,则进入产品管理总页面main.jsp。若不成功仍退回index.jsp
2. 注册
用户默认主页index.jsp , 可选择注册功能 ,若注册,则进入 register.jsp
3. 管理产品(增加,删除,查看)
登录成功后,进入产品管理总页面main.jsp。第一次进入main.jsp,默认显示所有产品列表。在此页面上更实现 查询某个产品记录,添加产品,批量删除,选中一项产品查看详情,实现分页功能。
3.1 添加产品
3.2 查询"圣女果"
3.3 选择“香蕉” ,点击 “查看”
4. 退出
用户点击“退出”时,清除session,退回主页面index.jsp
5. 过滤器
若用户没有登录成功,而直接访问 main.jsp 或 addProduct.jsp ,则被过滤器过滤到 index.jsp . 因为有成功登录,验证其身份后,才有权利访问产品和管理产品。否则将被过滤到默认主页index.jsp.
例如:在地址栏直接输入:http://192.168.0.103:8080/xianfengProject/main.jsp,则被过滤到index.jsp
-------------------------------------------------------------------------------
项目环境:
操作系统: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)
product (proid , proname, proprice , proaddress , proimage)表结构:
userinfo (id , username , pswd)表结构如下:
2. MyEclipse 工程目录
----------------------------------------------------------------------------------------------------------------------
1. index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>先锋管理系统欢迎您</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function login(){
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();
}
</script>
</head>
<body>
<div style="text-align:center">
<form name="form1" action="" method="post">
<table style="margin:auto">
<tr>
<td colspan="2">
先锋管理系统欢迎你!
</td>
</tr>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"></input></td>
</tr>
<tr>
<td>密 码:</td>
<td><input type="password" name="pswd"></input></td>
</tr>
<tr>
<td colspan="2" align="center">
<button type="button" name="" value="" onclick="login()">登录</button>
<button type="button" name="" value="" onclick="javascript:location.href=‘register.jsp‘">注册</button>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
2. register.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>注册新用户</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function dosubmit(){
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;
}
</script>
</head>
<body>
<div style="text-align:center">
<form action="" name="form1" method="post">
<table style="margin:auto">
<tr>
<td colspan="3">
用户注册
</td>
</tr>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"></input></td>
<td>必须填写!</td>
</tr>
<tr>
<td>密 码:</td>
<td><input type="password" name="pswd"></input></td>
<td>必须填写!</td>
</tr>
<tr>
<td colspan="3" align="center">
<button type="button" name="" onclick="dosubmit()" >确定</button>
<button type="button" name="" value="" onclick="javascript:location.href=‘index.jsp‘" >返回</button>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
3.main.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.util.*" %>
<%@ page import="com.product.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
//获取 session 中的 username;
String username = (String)session.getAttribute("username");
//获取从 servlet ProductActiion 中 传递的参数(数据库查询的结果)
List<Map<String,Object>> list =(List<Map<String,Object>>) 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);
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>产品管理</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function searchProduct(){
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";
}
</script>
</head>
<body>
<div>
<table width=60% align="center">
<tr>
<td align="left"><font size=2>欢迎您的光临,<%=username%><br><a href="javascript:logout();">退出</a></font></td>
</tr>
<tr>
<td align="center">
<form name = "form2" action="" method="post">
<table>
<tr>
<td colspan="2">产品信息查询</td>
</tr>
<tr>
<td >产品名称</td>
<td ><input type="text" name="proname" value="<%= productName!=null?productName:"" %>"/></td>
</tr>
<tr>
<td colspan="2"