简单的Java web项目(mysql+jsp可实现增删改查)

1.创建数据库:

用户名:root;

密码:123456;(如果密码为空或是其他密码,则需要修改密码。)

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

字符集为utf-8,一般在字符集最后一个。

表一:userinfo(类型为:id,username,pswd)为用户登录数据库。

表二:product(类型为:proid,proname,proprice,proaddress,proimage)为系统信息数据库。

 userinfo表结构如下:(注意:必须勾选自动递增选项,否则无法注册成功)

 product表结构如下:

 2.MyEclipse(ruanjianProject)工程项目目录:

配置:Tomcat8.5和jdk1.8以上

注意:要先创建lib文件夹,再进行导包。

1.commons-fileupload-1.3.1

2.commons-io-2.4

3.mysql-connector-java-5.1.7-bin

4.servlet-2_5-api

最后右击/Build path/奶瓶形状(默认为第一个),则会生成Web App Libraries

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

(需要压缩包或者文本格式请联系楼主,楼主看到会一一回复)

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>
  <meta charset="UTF-8">
  <title>软件201班学生身份信息系统欢迎您</title>
	</head>		
		<style type="text/css">
			body
			{
				margin: 5px;
				background-color: beige;
				font-size: 15px;
			}
			img
			{
				width: 200px;
				margin: 5px;
				float: left;
			}
			span
			{
				font-family: 隶书;
				font-size: 100px;
				float: center;
				margin: 3px;
			}				
		</style>	
	<body>		
	<img src="image/01.jpg"></img>		
	<span>软件201班</span><br>
	<base href="<%=basePath%>"><br>
	<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">
   		软件201班学生身份信息系统欢迎你!
   		</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>
  <meta charset="UTF-8">
	</head>		
		<style type="text/css">
			body
			{
				margin: 5px;
				background-color: #ffcc99;
				font-size: 15px;
			}			
		</style>
    <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+"/";
String username = (String)session.getAttribute("username");
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){
	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>
  <meta charset="UTF-8">
	</head>		
		<style type="text/css">
			body
			{
				margin: 5px;
				background-color: #ffccff;
				font-size: 15px;
			}			
		</style>
    <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/Produc
评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Redamancity

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值