JSP内置对象实现表的增删查改

<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ page import="java.sql.*" %>
<html>
<head><title>www.xiongsheng.com,熊胜的主页</title>
<style type="text/css">
<!--
.STYLE6 {font-size: 15px}
.STYLE10 {font-size: 20px; font-weight: bold; }
-->
</style>
</head>
<script language="javascript">
function changeColor(obj,color){
obj.bgColor = color ;
}
</script>
<script language="javascript" src="<%=request.getContextPath()%>/js/dept_validate.js">
</script>
<body>
<%! 
public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver"; 
public static final String DBURL = "jdbc:oracle:thin: @xiongsheng :1521:xiongsheng"; 
public static final String DBUSER = "xiong" ; 
public static final String DBPASSWORD = "xs1990721" ; 
%>
<%
Connection conn = null ;
PreparedStatement pstmt = null ;
ResultSet rs = null ;
%>
<%
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
%>
<center>
<h1><font color="red">部门信息列表</font></h1>
<form action="dept_insert_do.jsp" method="post" onsubmit="return validate(this)">
<TABLE BORDER="1" cellpadding="5" cellspacing="0" bgcolor="F2F2F2" width="100%">
<TR onMouseOver="changeColor(this,'blue')" onMouseOut="changeColor(this,'F2F2F2')">
<td align="center" valign="middle"><span class="STYLE10">部门编号</span></td>
   <td align="left" valign="middle">
  <input type="text" name="deptno" size="2" maxlength="2" onblur="validateDeptno(this.value)">
  </td>

</TR>
<TR onMouseOver="changeColor(this,'blue')" onMouseOut="changeColor(this,'F2F2F2')">
<td align="center" valign="middle"><span class="STYLE10">部门名称</span></td>
   <td align="left" valign="middle">
  <input type="text" name="dname" onblur="validateDname(this.value)">
  </td>

</TR>
<TR onMouseOver="changeColor(this,'blue')" onMouseOut="changeColor(this,'F2F2F2')">
<td align="center" valign="middle"><span class="STYLE10">部门人数</span></td>
   <td align="left" valign="middle">
  <input type="text" name="count" onblur="validateDname(this.value)">
  </td>

</TR>
<TR onMouseOver="changeColor(this,'blue')" onMouseOut="changeColor(this,'F2F2F2')">
<td align="center" valign="middle"><span class="STYLE10">部门位置</span></td>
   <td align="left" valign="middle"><input type="text" name="loc"  onblur="validateLoc(this.value)"></td>

</TR>
<TR onMouseOver="changeColor(this,'blue')" onMouseOut="changeColor(this,'F2F2F2')">
<td align="center" valign="middle" colspan="3">
<input type="submit" value="添加">
<input type="reset" value="重置">
</td>
</TR>
 </TABLE>
</form>
<TABLE BORDER="1" cellpadding="5" cellspacing="0" bgcolor="F2F2F2" width="100%">
<TR onMouseOver="changeColor(this,'white')" onMouseOut="changeColor(this,'F2F2F2')">
<td align="center" valign="middle"><span class="STYLE10">编号</span></td>
<td align="center" valign="middle"><span class="STYLE10">名称</span></td>
<td align="center" valign="middle"><span class="STYLE10">人数</span></td>
<td align="center" valign="middle"><span class="STYLE10">位置</span></td>
<td align="center" valign="middle"><span class="STYLE10">操作</span></td>
</TR>
<%
String sql = "SELECT deptno,dname,count,loc FROM dept " ;
pstmt = conn.prepareStatement(sql) ;
rs = pstmt.executeQuery() ;
%>
<%
while(rs.next()){
int deptno = rs.getInt(1) ;
String dname = rs.getString(2) ;
String count=rs.getString(3);
String loc = rs.getString(4) ;
%>
<form action="dept_update_do.jsp" method="post">
<TR onMouseOver="changeColor(this,'white')" onMouseOut="changeColor(this,'F2F2F2')">
<td align="center" valign="middle"><span class="STYLE6"><%=deptno%></span></td>
<td align="center" valign="middle"><span class="STYLE6"><input type="text" name="dname" value="<%=dname%>"></span></td>
<td align="center" valign="middle"><span class="STYLE6"><input type="text" name="count" value="<%=count%>"></span></td>
<td align="center" valign="middle"><span class="STYLE6"><input type="text" name="loc" value="<%=loc%>"></span></td>
<td align="center" valign="middle"><span class="STYLE6">
<input type="hidden" name="deptno" value="<%=deptno%>">
<input type="submit" value="修改">
   </span></td>
<td align="center" valign="middle"><span class="STYLE6">
<a href="dept_delete_do.jsp?deptno=<%=deptno%>">删除</a>
   </span></td>
</TR>
</form>
<%
}
%>
</table>
<%
conn.close() ;
%>
</center>
</body>

</html>

JSP内置对象实现表的增删查改_第1张图片

你可能感兴趣的:(JSP内置对象实现表的增删查改)