jsp操作MySQL实现查询/插入/删除功能示例

直接贴代码吧:
首先,index_test.jsp页面的代码如下:

复制代码 代码如下:


<%@ page language="java" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8"%>&nbsp;
<%&nbsp;
&nbsp; &nbsp;request.setCharacterEncoding("UTF-8");&nbsp;
&nbsp; &nbsp;response.setCharacterEncoding("UTF-8");&nbsp;
&nbsp; &nbsp;response.setContentType("text/html;charset=utf-8");&nbsp;
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>人员操作</title>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<style>
#popDivAdd,#popDivDelete {
position: absolute;
visibility: hidden;
overflow: hidden;
border: 2px solid #AEBBCA;
background-color: #EEF1F8;
cursor: move;
padding: 1px;
}

#popTitle {
background: #9DACBF;
height: 20px;
line-height: 20px;
padding: 1px;
}

#popForm {
padding: 2px;
}

.title_left {
font-weight: bold;
padding-left: 5px;
float: left;
}

.title_right {
float: right;
}

#popTitle .title_right a {
color: #000;
text-decoration: none;
}

#popTitle .title_right a:hover {
text-decoration: underline;
color: #FF0000;
}
</style>
<script>
function showPopup(type) {//弹出层
//var objDiv = null;//objDiv是目标div
if(type == 'add'){
objDiv = document.getElementById("popDivAdd");
}
else
if(type = 'delete'){
objDiv = document.getElementById("popDivDelete");
}
objDiv.style.top = "50px";//设置弹出层距离上边界的距离
objDiv.style.left = "200px";//设置弹出层距离左边界的距离
objDiv.style.width = "300px";//设置弹出层的宽度
objDiv.style.height = "220px";//设置弹出层的高度
//objDiv.style.display = "block";
objDiv.style.visibility = "visible";
}
function hidePopup(type) {//关闭层
//var objDiv = null;//objDiv是目标div
if(type == 'add'){
objDiv = document.getElementById("popDivAdd");
}
else&nbsp;
if(type = 'delete'){
objDiv = document.getElementById("popDivDelete");
}
objDiv.style.visibility = "hidden";
}
</script>
</head>
<body>
<!-- 表单div -->
<form action="insert_test.jsp" method="post">
<p>
&nbsp;ID :<input type="text" value="0" /></br>&nbsp;
姓名:<input type="text" value="" /></br>
性别:<input type="text" value="" /></br>
年龄:<input type="text" value="" /></br>
</p>&nbsp;
&nbsp;&nbsp;&nbsp; <input type="submit" value="提交" />&nbsp;&nbsp;
&nbsp;&nbsp; <input type="reset" value="重置" />&nbsp;&nbsp;
&nbsp;&nbsp; <input type="reset" value="取消" />
</form>
</div>
</div>
<div><!-- 删除人员的div -->
<div><!-- 标题div -->
<span>删除人员</span> <span>
<a href="#">关闭</a> </span>
</div>
<div><!-- 表单div -->
<form action="delete_test.jsp" method="post">
<p>
&nbsp;ID :<input type="text" value="" /> </br>&nbsp;
姓名:<input type="text" value="" /> </br>
</p>&nbsp;
&nbsp;&nbsp;&nbsp; <input type="submit" value="提交" />&nbsp;&nbsp;
&nbsp;&nbsp; <input type="reset" value="重置" />&nbsp;&nbsp;
&nbsp;&nbsp; <input type="reset" value="取消" />
</form>
</div>
</div>
<p>
<input type="button" value="查询" />&nbsp;&nbsp;
<input type="button" value="添加" />&nbsp;&nbsp;
<input type="button" value="删除" />
</p>

<script type="text/javascript">
/*-------------------------鼠标左键拖动---------------------*/
/*--------当不需要实现此功能时,可以将这一部分代码删除------------*/
var objDiv = document.getElementById("popDiv");
var isIE = document.all ? true : false;//判断浏览器类型
document.onmousedown = function(evnt) {//当鼠标左键按下后执行此函数
var evnt = evnt ? evnt : event;
if (evnt.button == (document.all ? 1 : 0)) {
mouseD = true;//mouseD为鼠标左键状态标志,为true时表示左键被按下
}
}

objDiv.onmousedown = function(evnt) {
objDrag = this;//objDrag为拖动的对象
var evnt = evnt ? evnt : event;
if (evnt.button == (document.all ? 1 : 0)) {
mx = evnt.clientX;
my = evnt.clientY;
objDiv.style.left = objDiv.offsetLeft + "px";
objDiv.style.top = objDiv.offsetTop + "px";
if (isIE) {
objDiv.setCapture();
//objDiv.filters.alpha.opacity = 50;//当鼠标按下后透明度改变
} else {
window.captureEvents(Event.MOUSEMOVE);//捕获鼠标拖动事件
//objDiv.style.opacity = 0.5;//当鼠标按下后透明度改变
}
}
}
document.onmouseup = function() {
mouseD = false;//左键松开
objDrag = "";
if (isIE) {
objDiv.releaseCapture();
//objDiv.filters.alpha.opacity = 100;//当鼠标左键松开后透明度改变
} else {
window.releaseEvents(objDiv.MOUSEMOVE);//释放鼠标拖动事件
//objDiv.style.opacity = 1;//当鼠标左键松开后透明度改变
}
}

document.onmousemove = function(evnt) {
var evnt = evnt ? evnt : event;
if (mouseD == true && objDrag) {
var mrx = evnt.clientX - mx;
var mry = evnt.clientY - my;
objDiv.style.left = parseInt(objDiv.style.left) + mrx + "px";
objDiv.style.top = parseInt(objDiv.style.top) + mry + "px";
mx = evnt.clientX;
my = evnt.clientY;
}
}
</script>
</body>
</html>


query_test.jsp页面代码如下:

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzfjgy.html