//login.jsp
<%@ page language="java" pageEncoding="gbk"%>
<%
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>
<base href="<%=basePath%>">
</head>
<body>
<form method="post" actio="checklogin.jsp" name="myform">
<table>
<tr>
<td>用户名:</td><td><input type="text" name="username"></td>
</tr>
<tr>
<td>密码:</td><td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="submit" value="提交"></td><td><input type="reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html>
//checklogin.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>
<%
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>
<base href="<%=basePath%>">
<title>My JSP 'checklogin.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>
<%
String name=request.getParameter("username");
if(name==null) name="";
byte a[]=name.getBytes("ISO-8859-1");
name=new String(a);
String userpass=request.getParameter("password");
if(userpass==null) userpass="";
byte b[]=userpass.getBytes("ISO-8859-1");
userpass=new String(b);
%>
<jsp:useBean id="user" class="news.conn" scope="page">
</jsp:useBean>
<%
String sql="insert into user values('"+name+"','"+userpass+"')";
user.executeUpdate(sql);
user.close();
%>
<%
try{
ResultSet rs;
String sqll="select * from user";
out.print("<Table Border>");
out.print("<TR>");
out.print("<TH width=100>"+"用户名"+"</th>");
out.print("<TH width=100>"+"密码"+"</th>");
out.print("</TR>");
rs=user.executeQuery(sqll);
while(rs.next())
{
out.print("<TR>");
out.print("<TD >"+rs.getString(1)+"</TD>");
out.print("<TD >"+rs.getString(2)+"</TD>");
out.print("</TR>");
}
out.print("</Table>");
user.close();
}catch(SQLException e){}
%>
</body>
</html>
//conn.java
package news;
import java.sql.*;public class conn {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; //设置JDBC驱动类型
String sConnStr = "jdbc:odbc:grade"; //设置连接数据库服务器字符
Connection connect = null;
ResultSet rs = null; public conn() {
try {
Class.forName(sDBDriver);
}
catch(ClassNotFoundException e) {}
}
public ResultSet executeQuery(String sql) {
try {
connect = DriverManager.getConnection(sConnStr); //建立连接
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(sql); //执行数据查询语句
}
catch(SQLException ex) {}
return rs;
}
public int executeUpdate(String sql) {
int result = 0;
try {
connect = DriverManager.getConnection(sConnStr);
Statement stmt = connect.createStatement();
result = stmt.executeUpdate(sql); //执行数据操作语句
}
catch(SQLException ex) {}
return result;
}
public void close(){
if(connect!=null){
try{
connect.close(); //关闭连接、释放资源
}catch(SQLException ex) {}
}
}}
数据源配置好了,Access数据库
怎么老是写不进数据库啊
哪个高手帮小弟看看
<%@ page language="java" pageEncoding="gbk"%>
<%
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>
<base href="<%=basePath%>">
</head>
<body>
<form method="post" actio="checklogin.jsp" name="myform">
<table>
<tr>
<td>用户名:</td><td><input type="text" name="username"></td>
</tr>
<tr>
<td>密码:</td><td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="submit" value="提交"></td><td><input type="reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html>
//checklogin.jsp
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>
<%
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>
<base href="<%=basePath%>">
<title>My JSP 'checklogin.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>
<%
String name=request.getParameter("username");
if(name==null) name="";
byte a[]=name.getBytes("ISO-8859-1");
name=new String(a);
String userpass=request.getParameter("password");
if(userpass==null) userpass="";
byte b[]=userpass.getBytes("ISO-8859-1");
userpass=new String(b);
%>
<jsp:useBean id="user" class="news.conn" scope="page">
</jsp:useBean>
<%
String sql="insert into user values('"+name+"','"+userpass+"')";
user.executeUpdate(sql);
user.close();
%>
<%
try{
ResultSet rs;
String sqll="select * from user";
out.print("<Table Border>");
out.print("<TR>");
out.print("<TH width=100>"+"用户名"+"</th>");
out.print("<TH width=100>"+"密码"+"</th>");
out.print("</TR>");
rs=user.executeQuery(sqll);
while(rs.next())
{
out.print("<TR>");
out.print("<TD >"+rs.getString(1)+"</TD>");
out.print("<TD >"+rs.getString(2)+"</TD>");
out.print("</TR>");
}
out.print("</Table>");
user.close();
}catch(SQLException e){}
%>
</body>
</html>
//conn.java
package news;
import java.sql.*;public class conn {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; //设置JDBC驱动类型
String sConnStr = "jdbc:odbc:grade"; //设置连接数据库服务器字符
Connection connect = null;
ResultSet rs = null; public conn() {
try {
Class.forName(sDBDriver);
}
catch(ClassNotFoundException e) {}
}
public ResultSet executeQuery(String sql) {
try {
connect = DriverManager.getConnection(sConnStr); //建立连接
Statement stmt = connect.createStatement();
rs = stmt.executeQuery(sql); //执行数据查询语句
}
catch(SQLException ex) {}
return rs;
}
public int executeUpdate(String sql) {
int result = 0;
try {
connect = DriverManager.getConnection(sConnStr);
Statement stmt = connect.createStatement();
result = stmt.executeUpdate(sql); //执行数据操作语句
}
catch(SQLException ex) {}
return result;
}
public void close(){
if(connect!=null){
try{
connect.close(); //关闭连接、释放资源
}catch(SQLException ex) {}
}
}}
数据源配置好了,Access数据库
怎么老是写不进数据库啊
哪个高手帮小弟看看
<form method="post" action="checklogin.jsp" name="myform">
看看页面是否由login.jsp 挑战到了checklogin.jsp,一步一步的调试,肯定能够找出错误的