JSP文件上传,PAGE分页,SQL2K驱动类,数据库连接及PROC
[此贴子已经被作者于2006-10-15 7:56:19编辑过]
----------------解决方案--------------------------------------------------------
库连接详解:
<%
/*关键字:
import
Class.forName
DriverManager类
Connection接口
Statement接口
ResultSet接口
*/
//①在使用Class.forName之前,应先使用import导入java.sql包
import.java.sql.*;
//②装载驱动
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//③DriverManager[驱动程序管理器]激发getConnection方法,建立与数据库的连接; Connecction对象代表与数据库的连接,Conn为实例Connection对象JSP编程中使用最频繁的接口之一大家一定要掌握(它的方法较多)
String url="jdbc:odbc:conntest";//数据源名字
Connection conn = DriverManager.getConnection(url,"","");
//④Java.sql.Statement提供在基层连接上运行SQL语句,并且访问结果。Connection接口提供了生成Statement的方法。
Statement s = conn.createStatement();
//⑤ResultSet保存着查询的结果集,提供了逐行访问结果的方法
ResultSet rs = s.executeQuery("select * from titles");
%>
----------------解决方案--------------------------------------------------------
点击下拉列表图片名在当前页预览:
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<link rel="stylesheet" href="text.css" type="text/css">
<script language="javascript">
function check(){
if(text.username.value==""){
alert("请输入姓名");
return false;
}
if(text.username.value.length>20){
alert("姓名不超过20位");
return false;
}
if(text.email.value!=""){
if(text.email.value.length>20){
alert("邮件位数不超过20");
return false;
}
}
if(text.qq.value!=""){
if(text.qq.value.length>9){
alert("qq位数不超过9");
return false;
}
}
if(text.url.value!=""){
if(text.url.value.length>24){
alert("url位数不超过24");
return false;
}
}
if(text.title.value==""){
alert("请输入标题");
return false;
}
if(text.title.value.length>40){
alert("标题不超过40位");
return false;
}
if(text.text.value==""){
alert("请输入内容");
return false;
}
if(text.text.value.length>400){
alert("内容不超过400位");
return false;
}
return true;
}
</script>
</head>
<body leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" bgcolor="#ffffff">
<br>
<div align="center">
<center>
<table align=center border=0 cellPadding=0 cellSpacing=0 width=500>
<tr>
<td width=134 height=37><IMG height=37 src="images/top_left.gif" width=134></td>
<td width="100%" background=images/top_middle.gif height=37 valign="middle">
<p align="center"><font color="#FFFFFF">欢迎使用!</font></td>
<td width=49 height=37><IMG height=37 src="images/top_right.gif" width=49></td>
</tr>
</table>
</center>
</div>
<div align=center>
<center>
<table align=center border=0 cellPadding=0 cellSpacing=0 width=500 height=113>
<tr>
<td width=11 background="images/middle_left.gif" height=113> </td>
<td width=478 align="center" height=1>
<br>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#009933" width="94%" id="AutoNumber3" height="126">
<tr>
<td width="100%" height="126" align="center" valign="top">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#009933" width="100%" id="AutoNumber4" height="28">
<tr>
<td width="100%" height="28" background="images/note_bg.gif">
<p align="center">欢迎留言!(“<font color="#FF0000">*</font>”是必填写的字段)</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber5" height="243" bgcolor="#F7FEF6">
<form name="text" method="post" action="load.jsp" onsubmit="return check();">
<tr>
<td width="100%" height="88" valign="top">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber6" height="87">
<tr>
<td width="15%" height="29"><font color="#99BB99"> </font><font color="#FF0000">*</font><font color="#99BB99">
姓名:</font></td>
<td width="37%" height="29"> <input type="text" name="username" size="16" class=yao></td>
<td width="14%" height="29">
<p align="center"><font color="#99BB99">性别:</font></td>
<td width="34%" height="29"> <input type="radio" value="男" name="sex" checked><font color="#99BB99">男 </font> <input type="radio" value="女" name="sex"><font color="#99BB99">女</font></td>
</tr>
<tr>
<td width="15%" height="29">
<p align="center"><font color="#99BB99">E-mail</font></td>
<td width="37%" height="29"> <input type="text" name="email" size="20" class="yao"></td>
<td width="14%" height="29">
<p align="center"><font color="#99BB99">QQ</font></td>
<td width="34%" height="29"> <input type="text" name="qq" size=16 class="yao"></td>
</tr>
<tr>
<td width="14%" height="29">
<font color="#99BB99">主页:</font></td>
<td width="86%" height="29" colspan="3">
<input type="text" name="url" size="22" class="yao"> <font color="#99BB99">注意</font><font color="#FF0000">*</font><font color="#99BB99">为必填字段</font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" height="155" valign="top">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber7" height="167">
<tr>
<td width="29%" height="22">
<p align="right"><font color="#FF0000">*</font><font color="#99BB99">留言标题: </font></td>
<td width="71%" height="165" rowspan="3">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber8" height="175">
<tr>
<td width="100%" height="22"><font color="#99BB99"> <input type="text" name="title" size="28" class=yao maxlength="28"></font></td>
</tr>
<tr>
<td width="100%" height="125" valign="top">
<!--webbot bot="Validation" S-Data-Type="String" I-Maximum-Length="30" S-Validation-Constraint="Greater than or equal to" S-Validation-Value="30" --><textarea name="text" cols="40" rows="8" class="yao"></textarea></td>
</tr>
<tr>
<td width="100%" height="28" valign="center"> <input type="submit" value="提交"'> <input type="reset" value="重写"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="29%" height="22">
<p align="right"><font color="#FF0000">*</font><font color="#99BB99">留言内容:</font></td>
</tr>
<tr>
<td width="29%" height="123" align="center" valign="top">
<script language=JavaScript>
function changeimage()
{
document.showimages.src=document.text.image.value;
}
</script>
<img name=showimages src="images/image/01.gif" width="84" height="95">
<select style="position: absolute; left: 188; top: 328; width: 85px; height: 20px; clip:rect(2 114 20 2)" name="image" size="1" onChange="changeimage();" >
<option value="images/image/01.gif" selected>images 1</option><img src="">
<option value="images/image/02.gif">images 2</option>
<option value="images/image/03.gif">images 3</option>
<option value="images/image/04.gif">images 4</option>
<option value="images/image/05.gif">images 5</option>
<option value="images/image/06.gif">images 6</option>
<option value="images/image/07.gif">images 7</option>
<option value="images/image/08.gif">images 8</option>
<option value="images/image/09.gif">images 9</option>
<option value="images/image/10.gif">images 10</option>
<option value="images/image/11.gif">images 11</option>
<option value="images/image/12.gif">images 12</option>
<option value="images/image/13.gif">images 13</option>
<option value="images/image/14.gif">images 14</option>
<option value="images/image/15.gif">images 15</option>
<option value="images/image/16.gif">images 16</option>
<option value="images/image/17.gif">images 17</option>
<option value="images/image/18.gif">images 18</option>
<option value="images/image/19.gif">images 19</option>
<option value="images/image/20.gif">images 20</option>
<option value="images/image/21.gif">images 21</option>
</select>
</td>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<p><br>
</td>
<td width=11 background="images/middle_left.gif" height=113> </td>
</tr>
</table>
</center>
</div>
<div align=center>
<center>
<table border=0 cellpadding=0 cellspacing=0 width=500>
<tr>
<td width=133 height=72><IMG height=72 src="images/bottom_left.gif" width=133></td>
<TD width="100%" background=images/bottom_middle.gif height=72>
<font color="#FFFFFF">All Rights Reserved.Copyleft © 2001-2003
<a href="http://www.pethome.com"><font color="#FFFFFF">www.NTsky.com</font></a></font><a href="http://www.pethome.com"><font color="#FFFFFF">
</font></a> </TD>
<td width=22 height=72><IMG height=72 src="images/bottom_right.gif" width=22></td>
</tr>
</table>
</center>
</div>
</body>
</html>
----------------解决方案--------------------------------------------------------
嘿嘿,不错,不过球球~你也应该看看一些框架了,比如Hibernate之类什么的,都不见你讨论过
----------------解决方案--------------------------------------------------------