jsp中怎样连接数据库 5
<html><head><basehref="<%=basePath%>"><title>MyJSP'index.jsp'startingpage</title><met...
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</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">
-->
</head>
<body>
<form name="example" id="example" method="post" action="result.jsp" >
<table bordercolor="pink" border="3" align="center">
<caption><b>登录 </b></caption>
<tr>
<td width="48">用户名</td>
<td width="289">
<input name="uname" type="text" id="uname" value=""><span id="unameinfo"></span>
</td>
</tr>
<tr>
<td><div align="center">密 码</div></td>
<td>
<input name="password" type="password" id="password" value=""><span id="passwordinfo"></span>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="button1" type="button" value="登录" onclick="reg()">
<input name="botton2"type="reset" value="重置" >
<input type="button" value="注册" onclick="zhuce()">
<!-- <input name="botton3" type="button" value="注册" onclick="reg()"/>-->
</td>
</tr>
</table>
</form>
</body>
<script language="javascript">
function zhuce(){
window.open("login.jsp");
}
function reg(){
var uname = document.getElementById("uname").value;
var password = document.getElementById("password").value;
if(uname==""){
var obj = document.getElementById("unameinfo");
obj.innerText = "请输入用户姓名";
return;
}
if(password==""){
var obj = document.getElementById("passwordinfo");
obj.innerText = "请输入密码";
return;
}
<%
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
DBstart db = new DBstart();
String uname = new String(request.getParameter("uname").getBytes("ISO-8859-1"),"UTF-8");
try{
conn = db.startDb();
String sql = "select * from users ";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
if(uname.equals(rs.getString(1))){
if(uname.equals(rs.getString(2))){
%>
var form1 = document.getElementById("example");
form1.submit();
<%
}
}
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
db.stopDb(rs,ps,conn);
}
%>
}
</script>
</html> 展开
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</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">
-->
</head>
<body>
<form name="example" id="example" method="post" action="result.jsp" >
<table bordercolor="pink" border="3" align="center">
<caption><b>登录 </b></caption>
<tr>
<td width="48">用户名</td>
<td width="289">
<input name="uname" type="text" id="uname" value=""><span id="unameinfo"></span>
</td>
</tr>
<tr>
<td><div align="center">密 码</div></td>
<td>
<input name="password" type="password" id="password" value=""><span id="passwordinfo"></span>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="button1" type="button" value="登录" onclick="reg()">
<input name="botton2"type="reset" value="重置" >
<input type="button" value="注册" onclick="zhuce()">
<!-- <input name="botton3" type="button" value="注册" onclick="reg()"/>-->
</td>
</tr>
</table>
</form>
</body>
<script language="javascript">
function zhuce(){
window.open("login.jsp");
}
function reg(){
var uname = document.getElementById("uname").value;
var password = document.getElementById("password").value;
if(uname==""){
var obj = document.getElementById("unameinfo");
obj.innerText = "请输入用户姓名";
return;
}
if(password==""){
var obj = document.getElementById("passwordinfo");
obj.innerText = "请输入密码";
return;
}
<%
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
DBstart db = new DBstart();
String uname = new String(request.getParameter("uname").getBytes("ISO-8859-1"),"UTF-8");
try{
conn = db.startDb();
String sql = "select * from users ";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
if(uname.equals(rs.getString(1))){
if(uname.equals(rs.getString(2))){
%>
var form1 = document.getElementById("example");
form1.submit();
<%
}
}
}
}
catch(Exception e){
e.printStackTrace();
}
finally{
db.stopDb(rs,ps,conn);
}
%>
}
</script>
</html> 展开
1个回答
展开全部
这个DBstart的数据库参数连接类贴出来看看。
还有当前这个页面里没有引用JSP页的头部PAGE指令,更没有导入SQL相关的包。
还有当前这个页面里没有引用JSP页的头部PAGE指令,更没有导入SQL相关的包。
更多追问追答
追问
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/user","root","123456" );
其他的贴不上了
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/user","root","123456" );
数据库的连接过程我另外建了java程序写的
其他的贴不上了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询